"""Stripe configuration and pricing plans."""
import stripe
from typing import Dict, List
from shared.config import settings

# Initialize Stripe
stripe.api_key = settings.stripe_secret_key

# Pricing plans configuration
PRICING_PLANS = {
    "free": {
        "name": "Free",
        "price": 0,
        "price_id": None,  # No Stripe price for free tier
        "features": [
            "5 projects per month",
            "Basic audio generation",
            "Standard video templates",
            "720p export quality",
            "Community support"
        ],
        "limits": {
            "projects_per_month": 5,
            "max_duration_seconds": 60,
            "max_resolution": "720p",
            "storage_gb": 1
        }
    },
    "pro": {
        "name": "Pro",
        "price": 2900,  # $29.00 in cents
        "price_id": None,  # Set via environment or Stripe dashboard
        "billing_period": "month",
        "features": [
            "Unlimited projects",
            "Advanced AI voices",
            "Premium video templates",
            "4K export quality",
            "Priority support",
            "Commercial license",
            "API access"
        ],
        "limits": {
            "projects_per_month": -1,  # Unlimited
            "max_duration_seconds": 600,  # 10 minutes
            "max_resolution": "4k",
            "storage_gb": 50
        }
    },
    "enterprise": {
        "name": "Enterprise",
        "price": 9900,  # $99.00 in cents
        "price_id": None,
        "billing_period": "month",
        "features": [
            "Everything in Pro",
            "Custom AI training",
            "White-label options",
            "Dedicated support",
            "SLA guarantee",
            "Custom integrations",
            "Team collaboration",
            "Advanced analytics"
        ],
        "limits": {
            "projects_per_month": -1,
            "max_duration_seconds": -1,  # Unlimited
            "max_resolution": "8k",
            "storage_gb": 500
        }
    }
}


def get_plan_limits(plan: str) -> Dict:
    """Get usage limits for a plan.
    
    Args:
        plan: Plan name (free, pro, enterprise)
        
    Returns:
        Dictionary of limits
    """
    return PRICING_PLANS.get(plan, PRICING_PLANS["free"])["limits"]


def get_plan_features(plan: str) -> List[str]:
    """Get features for a plan.
    
    Args:
        plan: Plan name
        
    Returns:
        List of feature descriptions
    """
    return PRICING_PLANS.get(plan, PRICING_PLANS["free"])["features"]


def format_price(cents: int) -> str:
    """Format price in cents to display string.
    
    Args:
        cents: Price in cents
        
    Returns:
        Formatted price string (e.g., "$29.00")
    """
    dollars = cents / 100
    return f"${dollars:.2f}"
