"""
Referral System Utils
"""
import uuid
from config.settings import REFERRAL_REWARD_COINS, REFERRAL_THRESHOLD


class ReferralCodeGenerator:
    """Generate unique referral codes"""
    
    @staticmethod
    def generate_code() -> str:
        """Generate unique referral code"""
        return str(uuid.uuid4())[:8].upper()
    
    @staticmethod
    def generate_referral_link(bot_username: str, referral_code: str) -> str:
        """Generate referral link"""
        return f"https://t.me/{bot_username}?start={referral_code}"
    
    @staticmethod
    def should_reward(referral_count: int) -> bool:
        """Check if user should receive reward"""
        return referral_count > 0 and referral_count % REFERRAL_THRESHOLD == 0
    
    @staticmethod
    def calculate_reward(referral_count: int) -> int:
        """Calculate reward coins"""
        if ReferralCodeGenerator.should_reward(referral_count):
            return REFERRAL_REWARD_COINS
        return 0


class ReferralValidator:
    """Validate referral operations"""
    
    @staticmethod
    def is_valid_referral(referrer_id: int, referred_id: int) -> bool:
        """Check if referral is valid"""
        # Cannot refer yourself
        if referrer_id == referred_id:
            return False
        return True
    
    @staticmethod
    def can_claim_reward(total_referrals: int) -> bool:
        """Check if user can claim reward"""
        return total_referrals >= REFERRAL_THRESHOLD
