package page

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 is authorized for deletion
type ValidateSiteForDeletionUseCase struct {
	siteRepo domainsite.Repository
	logger   *zap.Logger
}

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

// Execute validates the site for deletion operations
func (uc *ValidateSiteForDeletionUseCase) Execute(
	ctx context.Context,
	tenantID, siteID gocql.UUID,
) (*domainsite.Site, error) {
	// Get site from repository
	site, err := uc.siteRepo.GetByID(ctx, tenantID, siteID)
	if err != nil {
		uc.logger.Error("failed to get site", zap.Error(err))
		return nil, domainsite.ErrSiteNotFound
	}

	// Verify site is verified (skip for test mode)
	if site.RequiresVerification() && !site.IsVerified {
		uc.logger.Warn("site not verified", zap.String("site_id", siteID.String()))
		return nil, domainsite.ErrSiteNotVerified
	}

	return site, nil
}
