package site

import (
	"context"

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

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

// DeleteSiteUseCase handles site deletion
// DEPRECATED: This usecase is too simple but doesn't follow the refactored pattern.
// Use the service layer (service/site/delete.go) which orchestrates
// focused usecases: ValidateSiteForDeletionUseCase, DeleteSiteFromRepoUseCase.
// This will be removed after migration is complete.
type DeleteSiteUseCase struct {
	repo   domainsite.Repository
	logger *zap.Logger
}

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

// DeleteSiteInput is the input for deleting a site
type DeleteSiteInput struct {
	SiteID string
}

// DeleteSiteOutput is the output after deleting a site
type DeleteSiteOutput struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

// Execute deletes a site
func (uc *DeleteSiteUseCase) Execute(ctx context.Context, tenantID gocql.UUID, input *DeleteSiteInput) (*DeleteSiteOutput, error) {
	siteID, err := gocql.ParseUUID(input.SiteID)
	if err != nil {
		return nil, err
	}

	// Delete from repository (removes from all 4 tables)
	if err := uc.repo.Delete(ctx, tenantID, siteID); err != nil {
		uc.logger.Error("failed to delete site", zap.Error(err))
		return nil, err
	}

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

	return &DeleteSiteOutput{
		Success: true,
		Message: "Site deleted successfully",
	}, nil
}
