package site

import (
	"context"

	"github.com/gocql/gocql"
	"go.uber.org/zap"

	domainsite "codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/internal/domain/site"
)

// ValidateSiteForDeletionUseCase validates that a site exists and can be deleted
type ValidateSiteForDeletionUseCase struct {
	repo   domainsite.Repository
	logger *zap.Logger
}

// ProvideValidateSiteForDeletionUseCase creates a new ValidateSiteForDeletionUseCase
func ProvideValidateSiteForDeletionUseCase(
	repo domainsite.Repository,
	logger *zap.Logger,
) *ValidateSiteForDeletionUseCase {
	return &ValidateSiteForDeletionUseCase{
		repo:   repo,
		logger: logger,
	}
}

// Execute validates that a site exists before deletion
func (uc *ValidateSiteForDeletionUseCase) Execute(ctx context.Context, tenantID, siteID gocql.UUID) (*domainsite.Site, error) {
	site, err := uc.repo.GetByID(ctx, tenantID, siteID)
	if err != nil {
		uc.logger.Error("site not found for deletion",
			zap.String("site_id", siteID.String()),
			zap.Error(err))
		return nil, err
	}

	uc.logger.Debug("site validated for deletion",
		zap.String("site_id", siteID.String()),
		zap.String("domain", site.Domain))

	return site, nil
}
