import os


def _env_int(name, default):
    value = os.getenv(name)
    if value is None or value == "":
        return default
    return int(value)


def _env_bool(name, default):
    value = os.getenv(name)
    if value is None or value == "":
        return default
    return value.strip().lower() in ("1", "true", "yes", "on")


MYSQL_CONFIG = {
    "host": os.getenv("TICKET_MYSQL_HOST", "127.0.0.1"),
    "port": _env_int("TICKET_MYSQL_PORT", 3307),
    "database": os.getenv("TICKET_MYSQL_DATABASE", "smits"),
    "user": os.getenv("TICKET_MYSQL_USER", "root"),
    "password": os.getenv("TICKET_MYSQL_PASSWORD", "localpassword"),
    "charset": os.getenv("TICKET_MYSQL_CHARSET", "utf8"),
}


POSTGRES_CONFIG = {
    "host": os.getenv("TICKET_PG_HOST", "127.0.0.1"),
    "port": _env_int("TICKET_PG_PORT", 5433),
    "dbname": os.getenv("TICKET_PG_DATABASE", "ticket"),
    "user": os.getenv("TICKET_PG_USER", "postgres"),
    "password": os.getenv("TICKET_PG_PASSWORD", "localpassword"),
}


TELEGRAM_BOT_TOKEN = os.getenv("TICKET_TELEGRAM_TOKEN", os.getenv("TELEGRAM_BOT_TOKEN", ""))
TELEGRAM_ADMIN_ID = _env_int("TICKET_ADMIN_ID", 145645559)
ENABLE_NOTIFICATIONS = _env_bool("TICKET_ENABLE_NOTIFICATIONS", True)
