// Package handlers provides HTTP handlers for the rdev API.
package handlers

import (
	"context"

	"github.com/orchard9/rdev/internal/domain"
	"github.com/orchard9/rdev/internal/service"
)

// DomainServiceAdapter adapts ProjectInfraService to the DomainService interface.
type DomainServiceAdapter struct {
	svc *service.ProjectInfraService
}

// NewDomainServiceAdapter creates an adapter for the ProjectInfraService.
func NewDomainServiceAdapter(svc *service.ProjectInfraService) *DomainServiceAdapter {
	return &DomainServiceAdapter{svc: svc}
}

// ListDomains returns all domains for a project.
func (a *DomainServiceAdapter) ListDomains(ctx context.Context, projectID string) ([]*domain.ProjectDomain, error) {
	return a.svc.ListDomains(ctx, projectID)
}

// AddDomain adds a new domain to a project.
func (a *DomainServiceAdapter) AddDomain(ctx context.Context, req DomainAddRequest) (*domain.ProjectDomain, error) {
	return a.svc.AddDomain(ctx, service.AddDomainRequest{
		ProjectID:  req.ProjectID,
		Domain:     req.Domain,
		Type:       req.Type,
		RecordType: req.RecordType,
		Proxied:    req.Proxied,
	})
}

// RemoveDomain removes a domain from a project.
func (a *DomainServiceAdapter) RemoveDomain(ctx context.Context, projectID, fqdn string) error {
	return a.svc.RemoveDomain(ctx, projectID, fqdn)
}
