package site

import (
	"context"

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

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

// GetSiteUseCase handles getting a site by ID
type GetSiteUseCase struct {
	repo   domainsite.Repository
	logger *zap.Logger
}

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

// GetSiteInput is the input for getting a site
type GetSiteInput struct {
	ID string
}

// GetSiteOutput is the output after getting a site
type GetSiteOutput struct {
	Site *domainsite.Site
}

// Execute gets a site by ID
func (uc *GetSiteUseCase) Execute(ctx context.Context, tenantID gocql.UUID, input *GetSiteInput) (*GetSiteOutput, error) {
	siteID, err := gocql.ParseUUID(input.ID)
	if err != nil {
		return nil, err
	}

	site, err := uc.repo.GetByID(ctx, tenantID, siteID)
	if err != nil {
		uc.logger.Error("failed to get site", zap.Error(err))
		return nil, err
	}

	return &GetSiteOutput{Site: site}, nil
}
