from functools import lru_cache

from pydantic import computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    app_name: str = "Hospitality Orders Module"
    database_url: str = "postgresql+psycopg2://postgres:postgres@ordini-db:5432/orders_management"
    backend_cors_origins: str = "http://localhost:3300,http://localhost:3000"
    public_base_url: str = "http://localhost:8200"
    frontend_public_url: str = "http://localhost:3300"
    admin_password: str = "club"
    api_token: str = "ordini-demo-token"
    default_staff: str = "club"
    tenancy_registry_database: str = "/data/platform_registry.sqlite3"
    tenancy_session_duration_hours: int = 168

    model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", case_sensitive=False)

    @computed_field  # type: ignore[prop-decorator]
    @property
    def cors_origins_list(self) -> list[str]:
        return [item.strip() for item in self.backend_cors_origins.split(",") if item.strip()]


@lru_cache
def get_settings() -> Settings:
    return Settings()
