from functools import lru_cache
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict

class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_file=".env", case_sensitive=False, extra="ignore")
    environment: str = "development"
    service_name: str = "payment-service"
    api_v1_prefix: str = "/api/v1"
    database_url: str = Field(default="postgresql+asyncpg://superapp:superapp_password@localhost:5432/payment_db", validation_alias="PAYMENT_DATABASE_URL")
    database_url_sync: str = Field(default="postgresql+psycopg://superapp:superapp_password@localhost:5432/payment_db", validation_alias="PAYMENT_DATABASE_URL_SYNC")
    core_service_url: str = "http://localhost:8000"
    auth_required: bool = True
    entitlement_stub: bool = True
    keycloak_enabled: bool = True
    keycloak_server_url: str = "http://localhost:8080"
    keycloak_public_url: str = ""
    keycloak_realm: str = "superapp"
    jwt_algorithm: str = "RS256"
    jwt_audience: str = "account"
    jwt_verify_signature: bool = True
    cors_origins: str = "http://localhost:3000,http://127.0.0.1:3000"
    @property
    def keycloak_public_realm_url(self): return f"{(self.keycloak_public_url or self.keycloak_server_url).rstrip('/')}/realms/{self.keycloak_realm}"
    @property
    def cors_origin_list(self): return [x.strip() for x in self.cors_origins.split(",") if x.strip()]
@lru_cache
def get_settings(): return Settings()
settings = get_settings()
