// Package port defines interfaces (ports) for external dependencies.
package port

import (
	"context"

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

// DNSProvider manages DNS records for a zone.
type DNSProvider interface {
	// CreateRecord creates a DNS record.
	// If a record with the same name and type exists, it may be updated or error depending on implementation.
	CreateRecord(ctx context.Context, record domain.DNSRecord) (*domain.DNSRecord, error)

	// UpdateRecord updates an existing DNS record by ID.
	UpdateRecord(ctx context.Context, recordID string, record domain.DNSRecord) (*domain.DNSRecord, error)

	// UpsertRecord creates or updates a DNS record.
	// If a record with the same type and name exists, it updates it.
	// Otherwise, it creates a new record.
	// This is the preferred method for adding domain aliases where the record may already exist.
	UpsertRecord(ctx context.Context, record domain.DNSRecord) (*domain.DNSRecord, error)

	// DeleteRecord removes a DNS record by ID.
	DeleteRecord(ctx context.Context, recordID string) error

	// DeleteRecordByName removes a DNS record by type and name.
	// This is useful when you don't have the record ID.
	DeleteRecordByName(ctx context.Context, recordType, name string) error

	// GetRecord returns a single record by ID.
	GetRecord(ctx context.Context, recordID string) (*domain.DNSRecord, error)

	// ListRecords returns all records in the zone.
	// Optionally filter by record type.
	ListRecords(ctx context.Context, recordType string) ([]*domain.DNSRecord, error)

	// FindRecord finds a record by type and name.
	// Returns nil if not found (no error).
	FindRecord(ctx context.Context, recordType, name string) (*domain.DNSRecord, error)
}
