package site

import (
	"context"
	"fmt"

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

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

// DeleteSiteFromRepoUseCase deletes a site from the repository
type DeleteSiteFromRepoUseCase struct {
	repo   domainsite.Repository
	logger *zap.Logger
}

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

// Execute deletes a site from all repository tables
func (uc *DeleteSiteFromRepoUseCase) Execute(ctx context.Context, tenantID, siteID gocql.UUID) error {
	// Delete from repository (removes from all 4 Cassandra tables)
	if err := uc.repo.Delete(ctx, tenantID, siteID); err != nil {
		uc.logger.Error("failed to delete site from repository",
			zap.String("site_id", siteID.String()),
			zap.Error(err))
		return fmt.Errorf("failed to delete site: %w", err)
	}

	uc.logger.Info("site deleted from repository",
		zap.String("site_id", siteID.String()))

	return nil
}
