package services

import (
	"crypto/rand"
	"fmt"
	"math/big"
	"time"
)

type OTPService struct{}

func NewOTPService() *OTPService {
	return &OTPService{}
}

// GenerateOTP generates a 6-digit OTP
func (s *OTPService) GenerateOTP() (string, error) {
	max := big.NewInt(1000000) // 6 digits max
	n, err := rand.Int(rand.Reader, max)
	if err != nil {
		return "", fmt.Errorf("failed to generate OTP: %w", err)
	}
	
	// Format as 6-digit string with leading zeros
	otp := fmt.Sprintf("%06d", n.Int64())
	return otp, nil
}

// GetOTPExpiry returns the expiry time for OTP (10 minutes from now)
func (s *OTPService) GetOTPExpiry() time.Time {
	return time.Now().Add(10 * time.Minute)
}

// IsOTPExpired checks if OTP has expired
func (s *OTPService) IsOTPExpired(expiresAt time.Time) bool {
	return time.Now().After(expiresAt)
}

