from functools import lru_cache from pydantic import AnyHttpUrl, Field, field_validator from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore") project_name: str = "NexaFabric" environment: str = "development" api_host: str = "0.0.0.0" api_port: int = 8000 database_url: str = "sqlite:///./nexafabric.db" redis_url: str = "redis://localhost:6379/0" jwt_secret: str = Field(default="dev-only-change-me") jwt_access_token_minutes: int = 15 jwt_refresh_token_days: int = 14 token_encryption_key: str = "dev-only-change-me" demo_admin_password: str = "ChangeMe_UseEnvInstead" seed_demo_data: bool = False cors_origins: list[AnyHttpUrl] | list[str] = ["http://localhost:5173", "http://localhost:8080"] @field_validator("cors_origins", mode="before") @classmethod def parse_cors_origins(cls, value: str | list[str]) -> list[str]: if isinstance(value, str): return [origin.strip() for origin in value.split(",") if origin.strip()] return value @lru_cache def get_settings() -> Settings: return Settings()