import os
from pathlib import Path

from dotenv import load_dotenv


BASE_DIR = Path(__file__).resolve().parent.parent

load_dotenv(BASE_DIR / ".env")


def env(name, default=None):
    return os.environ.get(name, default)


def env_bool(name, default=False):
    value = env(name)
    if value is None:
        return default
    return value.lower() in {"1", "true", "yes", "on"}


def env_int(name, default):
    value = env(name)
    if value is None or value == "":
        return default
    return int(value)


def env_list(name, default=""):
    value = env(name, default)
    if not value:
        return []
    return [item.strip() for item in value.split(",") if item.strip()]
