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

import (
	"context"

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

// ProjectDomainRepository manages project-domain associations.
type ProjectDomainRepository interface {
	// Create adds a new domain association for a project.
	// Returns error if domain already exists (unique constraint).
	Create(ctx context.Context, pd *domain.ProjectDomain) error

	// GetByID retrieves a domain by its ID.
	GetByID(ctx context.Context, id int64) (*domain.ProjectDomain, error)

	// GetByDomain retrieves a domain by its FQDN.
	// Returns nil, nil if not found.
	GetByDomain(ctx context.Context, fqdn string) (*domain.ProjectDomain, error)

	// ListByProject returns all domains for a project.
	ListByProject(ctx context.Context, projectID string) ([]*domain.ProjectDomain, error)

	// GetPrimary returns the primary domain for a project.
	// Prefers primary_custom over primary_auto if both exist.
	GetPrimary(ctx context.Context, projectID string) (*domain.ProjectDomain, error)

	// Update modifies an existing domain record.
	Update(ctx context.Context, pd *domain.ProjectDomain) error

	// Delete removes a domain by ID.
	Delete(ctx context.Context, id int64) error

	// DeleteByDomain removes a domain by FQDN.
	DeleteByDomain(ctx context.Context, fqdn string) error

	// DeleteByProject removes all domains for a project.
	DeleteByProject(ctx context.Context, projectID string) error

	// Exists checks if a domain already exists.
	Exists(ctx context.Context, fqdn string) (bool, error)

	// CountByProject returns the number of domains for a project.
	CountByProject(ctx context.Context, projectID string) (int, error)
}

// SlugGenerator generates unique slugs for projects.
type SlugGenerator interface {
	// Generate creates a new unique slug.
	// Implementations should retry on collision.
	Generate(ctx context.Context) (string, error)

	// IsUnique checks if a slug is unique (not in use).
	IsUnique(ctx context.Context, slug string) (bool, error)
}
