"""
Configuration Stripe pour Web Sentinel
"""
import os
from dataclasses import dataclass
from typing import Dict


@dataclass
class StripePlan:
    """Configuration d'un plan d'abonnement"""
    name: str
    price_monthly: str  # Price ID Stripe pour abonnement mensuel
    price_yearly: str   # Price ID Stripe pour abonnement annuel
    lookup_key_monthly: str
    lookup_key_yearly: str
    features: list
    sast_limit: int
    tier: str


class StripeConfig:
    """Configuration Stripe centralisée"""
    
    # Clés API Stripe (à définir dans les variables d'environnement)
    STRIPE_SECRET_KEY = os.getenv('STRIPE_SECRET_KEY', '')
    STRIPE_PUBLISHABLE_KEY = os.getenv('STRIPE_PUBLISHABLE_KEY', '')
    STRIPE_WEBHOOK_SECRET = os.getenv('STRIPE_WEBHOOK_SECRET', '')
    
    # URL de base pour les redirections
    BASE_URL = os.getenv('BASE_URL', 'https://web-sentinel.taaazzz-prog.fr')
    
    # Plans d'abonnement
    # ⚠️ PRODUCTION: Price IDs LIVE créés le 30/10/2025
    PLANS: Dict[str, StripePlan] = {
        'pro': StripePlan(
            name='PRO',
            price_monthly='price_1SLlrK197Q6uWWA17onRkTlO',  # 9.99 EUR/mois (LIVE)
            price_yearly='price_1SLlrh197Q6uWWA1LA1bb8Pq',   # 99 EUR/an (LIVE)
            lookup_key_monthly='web_sentinel_pro_monthly',
            lookup_key_yearly='web_sentinel_pro_yearly',
            features=[
                'SAST: 100 fichiers/mois',
                'Support prioritaire',
                'Rapports détaillés',
                'Historique 90 jours'
            ],
            sast_limit=100,
            tier='pro'
        ),
        'enterprise': StripePlan(
            name='ENTERPRISE',
            price_monthly='price_1SLlsZ197Q6uWWA17JjMj7Uk',  # 49 EUR/mois (LIVE)
            price_yearly='price_1SLlss197Q6uWWA1KVOcdmjj',   # 490 EUR/an (LIVE)
            lookup_key_monthly='web_sentinel_enterprise_monthly',
            lookup_key_yearly='web_sentinel_enterprise_yearly',
            features=[
                'SAST: 500 fichiers/mois',
                'Support 24/7',
                'API dédiée',
                'Intégrations CI/CD',
                'Historique illimité',
                'SLA garanti'
            ],
            sast_limit=500,
            tier='enterprise'
        )
    }
    
    @classmethod
    def get_plan_by_lookup_key(cls, lookup_key: str) -> StripePlan:
        """Récupère un plan par sa lookup key"""
        for plan in cls.PLANS.values():
            if plan.lookup_key_monthly == lookup_key or plan.lookup_key_yearly == lookup_key:
                return plan
        raise ValueError(f"Plan non trouvé pour la lookup key: {lookup_key}")
    
    @classmethod
    def get_plan_by_tier(cls, tier: str) -> StripePlan:
        """Récupère un plan par son tier"""
        return cls.PLANS.get(tier.lower())
    
    @classmethod
    def is_configured(cls) -> bool:
        """Vérifie si Stripe est correctement configuré"""
        return bool(cls.STRIPE_SECRET_KEY and cls.STRIPE_PUBLISHABLE_KEY)
