from urllib.parse import quote_plus

from pydantic import computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict


class PostgresSettings(BaseSettings):
    model_config = SettingsConfigDict(env_prefix="db_", extra="ignore")

    PORT: int
    NAME: str
    USER: str
    HOST: str
    PASSWORD: str

    @computed_field
    @property
    def DATABASE_URL(self) -> str:
        return f"postgresql+asyncpg://{quote_plus(self.USER)}:{quote_plus(self.PASSWORD)}@{self.HOST}:{self.PORT}/{self.NAME}"
