"""
Application configuration module.
Loads settings from environment variables with sensible defaults.
"""
from functools import lru_cache
from typing import List
from pydantic_settings import BaseSettings


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

    # Application
    app_name: str = "FiHotelFlow"
    app_version: str = "1.0.0"
    debug: bool = True

    # Database
    database_url: str = "postgresql://nima3507_appfi:om4&F}lt~(3}@127.0.0.1:5432/nima3507_fihotelflow"
    database_url_async: str = "postgresql+asyncpg://nima3507_appfi:om4&F}lt~(3}@127.0.0.1:5432/nima3507_fihotelflow"

    # JWT Authentication
    secret_key: str = "6b948fb6e34cab30118d9d5cccfa84e46cf76db0ec096cf3a435d83126f64ffb"
    algorithm: str = "HS256"
    access_token_expire_minutes: int = 30
    refresh_token_expire_days: int = 7

    # CORS
    cors_origins: str = "https://hotelflow.app-fi.com,https://apihotelflow.app-fi.com/api"

    # Default Admin
    default_admin_email: str = "admin@fihotelflow.com"
    default_admin_password: str = "admin123"

    @property
    def cors_origins_list(self) -> List[str]:
        """Parse CORS origins string into a list."""
        return [origin.strip() for origin in self.cors_origins.split(",")]

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


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


settings = get_settings()
