from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    app_name: str = "mktapi.ose.tw"
    app_version: str = "0.1.0"
    app_env: str = "development"
    log_level: str = "INFO"
    api_prefix: str = "/api"

    db_host: str = "127.0.0.1"
    db_port: int = 5432
    db_database: str = "mkt.ose.tw"
    db_user: str = "mkt_ose"
    db_password: str = ""
    database_url: str = "postgresql+asyncpg://mkt_ose:@127.0.0.1:5432/mkt.ose.tw"

    directus_base_url: str = "https://mktcms.ose.tw"
    directus_admin_token: str | None = None
    directus_timeout: float = 15.0
    cors_allowed_origins: str = (
        "http://127.0.0.1:3000,http://localhost:3000,"
        "http://127.0.0.1:5173,http://localhost:5173,"
        "https://127.0.0.1:3000,https://localhost:3000,"
        "https://127.0.0.1:5173,https://localhost:5173,"
        "https://mkt.ose.tw"
    )

    @property
    def cors_allowed_origin_list(self) -> list[str]:
        """Return normalized CORS origins from a simple comma-separated env value."""

        return [
            origin.strip()
            for origin in self.cors_allowed_origins.split(",")
            if origin.strip()
        ]

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


settings = Settings()
