""" Configuration management for Silver Table Assistant. Centralized settings with environment variable support. """ import os from datetime import datetime from typing import List class Settings: """Application settings with environment variable support.""" def __init__(self): # Database Configuration self.supabase_url = os.getenv("SUPABASE_URL") self.supabase_service_role_key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") # AI Service Configuration self.openai_api_key = os.getenv("OPENAI_API_KEY") self.openai_base_url = os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1") # LiteLLM Configuration (alternative to OpenAI) self.litellm_base_url = os.getenv("LITELLM_BASE_URL") self.litellm_api_key = os.getenv("LITELLM_API_KEY") self.litellm_model = os.getenv("LITELLM_MODEL", "azure-gpt-4.1") # Payment Service Configuration self.stripe_secret_key = os.getenv("STRIPE_SECRET_KEY") self.stripe_publishable_key = os.getenv("STRIPE_PUBLISHABLE_KEY") self.stripe_webhook_secret = os.getenv("STRIPE_WEBHOOK_SECRET") self.stripe_default_currency = "twd" # Taiwan Dollar # Application Configuration self.frontend_url = os.getenv("FRONTEND_URL", "https://silver-esg.vercel.app") self.api_version = os.getenv("API_VERSION", "1.0.0") self.environment = os.getenv("ENVIRONMENT", "development") # Server Configuration self.host = os.getenv("HOST", "0.0.0.0") self.port = int(os.getenv("PORT", "8000")) # AI Model Configuration (for LiteLLM) self.ai_model_name = os.getenv("AI_MODEL_NAME", "azure-gpt-4.1") self.ai_max_tokens = 2000 self.ai_temperature = 0.7 # Currency Configuration self.default_currency = "twd" self.currency_symbol = "NT$" self.min_order_amount = 1000 # cents (NT$10) self.max_order_amount = 1000000 # cents (NT$10,000) self.min_donation_amount = 50 # NT$50 minimum for Stripe # Backwards-compatible uppercase constant self.MIN_DONATION_AMOUNT = self.min_donation_amount # Security Configuration self.jwt_secret_key = os.getenv("JWT_SECRET_KEY", "your-secret-key-here") self.access_token_expire_minutes = 30 # CORS Configuration self.cors_origins = self._parse_cors_origins() # Validation self._validate_required_settings() def _parse_cors_origins(self) -> List[str]: """Parse CORS origins from environment variable.""" origins_str = os.getenv("CORS_ORIGINS", "http://localhost:3000,http://localhost:5173") return [origin.strip() for origin in origins_str.split(",")] def _validate_required_settings(self): """Validate required environment variables.""" required_vars = [ "SUPABASE_URL", "SUPABASE_SERVICE_ROLE_KEY", "OPENAI_API_KEY", "STRIPE_SECRET_KEY", "STRIPE_WEBHOOK_SECRET" ] missing_vars = [] for var in required_vars: if not os.getenv(var): missing_vars.append(var) if missing_vars: raise ValueError(f"Missing required environment variables: {', '.join(missing_vars)}") def get_current_timestamp(self) -> str: """Get current timestamp in ISO format.""" return datetime.utcnow().isoformat() + "Z" def is_development(self) -> bool: """Check if running in development mode.""" return self.environment.lower() == "development" def is_production(self) -> bool: """Check if running in production mode.""" return self.environment.lower() == "production" def format_currency(self, amount_cents: int) -> str: """Format amount in cents to currency string.""" return f"{self.currency_symbol}{amount_cents / 100:.2f}" # Global settings instance settings = Settings()