# -*- coding: utf-8 -*-
from __future__ import annotations

import os


def env_str(name: str, default: str) -> str:
    value = os.environ.get(name)
    return value if value not in (None, "") else default


def env_int(name: str, default: int) -> int:
    value = os.environ.get(name)
    if value in (None, ""):
        return default
    try:
        return int(value)
    except ValueError:
        return default


APP_HOST = env_str("PAL_HOST", "127.0.0.1")
APP_PORT = env_int("PAL_PORT", 8787)
APP_DEBUG = env_str("PAL_DEBUG", "false").strip().lower() in {"1", "true", "yes", "on"}
MAX_UPLOAD_MB = env_int("PAL_MAX_UPLOAD_MB", 25)
AUTO_OPEN_BROWSER = env_str("PAL_AUTO_OPEN_BROWSER", "true").strip().lower() in {"1", "true", "yes", "on"}
