package site

import (
	"time"

	"go.uber.org/zap"

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

// UpdateSiteAPIKeyUseCase updates a site entity with new API key details
type UpdateSiteAPIKeyUseCase struct {
	logger *zap.Logger
}

// ProvideUpdateSiteAPIKeyUseCase creates a new UpdateSiteAPIKeyUseCase
func ProvideUpdateSiteAPIKeyUseCase(logger *zap.Logger) *UpdateSiteAPIKeyUseCase {
	return &UpdateSiteAPIKeyUseCase{
		logger: logger,
	}
}

// UpdateSiteAPIKeyInput contains the new API key details
type UpdateSiteAPIKeyInput struct {
	Site           *domainsite.Site
	NewAPIKeyHash  string
	NewKeyPrefix   string
	NewKeyLastFour string
}

// Execute updates the site entity with new API key details
func (uc *UpdateSiteAPIKeyUseCase) Execute(input *UpdateSiteAPIKeyInput) {
	input.Site.APIKeyHash = input.NewAPIKeyHash
	input.Site.APIKeyPrefix = input.NewKeyPrefix
	input.Site.APIKeyLastFour = input.NewKeyLastFour
	input.Site.UpdatedAt = time.Now()

	uc.logger.Debug("site entity updated with new API key",
		zap.String("site_id", input.Site.ID.String()),
		zap.String("new_prefix", input.NewKeyPrefix),
		zap.String("new_last_four", input.NewKeyLastFour))
}
