from pydantic import BaseSettings, PostgresDsn


class Config(BaseSettings):

    class Config:
        case_sensitive = False


class LogConfig(Config):
    level: str = "INFO"
    datetime_format: str = "%Y-%m-%d %H:%M:%S"

    class Config:
        case_sensitive = False
        fields = {
            "level": {
                "env": ["log_level"]
            },
        }


class TelegramConfig(Config):
    bot_token: str
    bot_name: str


class DBPoolConfig(Config):
    db_url: PostgresDsn
    min_size: int = 0
    max_size: int = 20
    max_queries: int = 1000
    max_inactive_connection_lifetime: int = 3600
    timeout: float = 10
    command_timeout: float = 10
    statement_cache_size: int = 1024
    max_cached_statement_lifetime: int = 3600


class DBConfig(Config):
    db_pool_config: DBPoolConfig


class ServiceConfig(Config):
    service_name: str = "reports_service"
    request_id_header: str = "X-Request-Id"

    log_config: LogConfig
    telegram_config: TelegramConfig
    db_config: DBConfig


def get_config() -> ServiceConfig:
    return ServiceConfig(
        log_config=LogConfig(),
        telegram_config=TelegramConfig(),
        db_config=DBConfig(db_pool_config=DBPoolConfig()),
    )
