package site

import (
	"crypto/rand"
	"encoding/base64"

	"go.uber.org/zap"
)

// GenerateVerificationTokenUseCase generates a verification token for domain verification
type GenerateVerificationTokenUseCase struct {
	logger *zap.Logger
}

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

// Execute generates a cryptographically secure verification token
func (uc *GenerateVerificationTokenUseCase) Execute() (string, error) {
	b := make([]byte, 16) // 16 bytes = 128 bits
	if _, err := rand.Read(b); err != nil {
		uc.logger.Error("failed to generate random bytes", zap.Error(err))
		return "", err
	}

	token := base64.RawURLEncoding.EncodeToString(b)
	verificationToken := "mvp_" + token // mvp = maplepress verify

	uc.logger.Info("verification token generated")
	return verificationToken, nil
}
