"""
Application settings configuration.
"""
import os
from typing import Optional
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """Application settings."""

    # WorkOS OAuth Configuration
    workos_api_key: str = os.getenv("WORKOS_API_KEY", "")
    workos_client_id: str = os.getenv("WORKOS_CLIENT_ID", "")

    # JWT Configuration
    jwt_issuer: str = os.getenv("JWT_ISSUER", "archie-api")
    jwt_audience: str = os.getenv("JWT_AUDIENCE", "archie-app")
    jwt_algorithm: str = os.getenv("JWT_ALGORITHM", "RS256")
    jwt_access_token_expires: int = int(os.getenv("JWT_ACCESS_TOKEN_EXPIRES", "3600"))  # 1 hour
    jwt_refresh_token_expires: int = int(os.getenv("JWT_REFRESH_TOKEN_EXPIRES", "604800"))  # 7 days

    # JWT Keys (from environment or files)
    jwt_private_key: Optional[str] = os.getenv("JWT_PRIVATE_KEY")
    jwt_public_key: Optional[str] = os.getenv("JWT_PUBLIC_KEY")
    jwt_private_key_path: Optional[str] = os.getenv("JWT_PRIVATE_KEY_PATH")
    jwt_public_key_path: Optional[str] = os.getenv("JWT_PUBLIC_KEY_PATH")

    # API Configuration
    api_host: str = os.getenv("API_HOST", "0.0.0.0")
    api_port: int = int(os.getenv("API_PORT", "5000"))
    api_debug: bool = os.getenv("API_DEBUG", "false").lower() == "true"

    # CORS Configuration
    cors_origins: str = os.getenv("CORS_ORIGINS", "*")

    class Config:
        env_file = ".env"
        case_sensitive = False
        extra = "allow"  # Allow extra fields from environment


# Global settings instance
settings = Settings()
