"""Application configuration."""

from functools import lru_cache
from pydantic_settings import BaseSettings
from typing import List, Optional


class Settings(BaseSettings):
    """Application settings from environment variables."""

    # Application
    app_name: str = "mockupAWS"
    app_version: str = "1.0.0"
    debug: bool = False
    log_level: str = "INFO"
    json_logging: bool = True

    # Database - default uses 'postgres' hostname for Docker, fallback to localhost for local dev
    database_url: str = "postgresql+asyncpg://postgres:postgres@postgres:5432/mockupaws"

    # Redis
    redis_url: str = "redis://localhost:6379/0"
    cache_disabled: bool = False

    # Celery
    celery_broker_url: str = "redis://localhost:6379/1"
    celery_result_backend: str = "redis://localhost:6379/2"

    # Pagination
    default_page_size: int = 20
    max_page_size: int = 100

    # Report Storage
    reports_storage_path: str = "./storage/reports"
    reports_max_file_size_mb: int = 50
    reports_cleanup_days: int = 30
    reports_rate_limit_per_minute: int = 10

    # JWT Configuration
    jwt_secret_key: str = "super-secret-change-in-production"
    jwt_algorithm: str = "HS256"
    access_token_expire_minutes: int = 30
    refresh_token_expire_days: int = 7

    # Security
    bcrypt_rounds: int = 12
    cors_allowed_origins: List[str] = ["http://localhost:3000", "http://localhost:5173", "http://localhost:8888"]
    cors_allowed_origins_production: List[str] = ["http://localhost:8888"]

    # Audit Logging
    audit_logging_enabled: bool = True
    audit_database_url: Optional[str] = None

    # Tracing
    jaeger_endpoint: Optional[str] = None
    jaeger_port: int = 6831
    otlp_endpoint: Optional[str] = None

    # Email
    smtp_host: str = "localhost"
    smtp_port: int = 587
    smtp_user: Optional[str] = None
    smtp_password: Optional[str] = None
    default_from_email: str = "noreply@mockupaws.com"

    class Config:
        env_file = ".env"
        case_sensitive = False
        extra = "ignore"


@lru_cache()
def get_settings() -> Settings:
    """Get cached settings instance."""
    return Settings()


settings = get_settings()
