"""
بارگذاری ساده‌ی فایل .env بدون نیاز به کتابخانه‌ی اضافی.
مقادیر محیطی واقعی (Environment Variables) همیشه بر فایل .env اولویت دارند.
"""
import os
from pathlib import Path


def load_env(path: Path) -> None:
    if not path.exists():
        return
    for raw in path.read_text(encoding='utf-8').splitlines():
        line = raw.strip()
        if not line or line.startswith('#') or '=' not in line:
            continue
        key, value = line.split('=', 1)
        key = key.strip()
        value = value.strip().strip('"').strip("'")
        os.environ.setdefault(key, value)


def env_bool(name: str, default: bool = False) -> bool:
    value = os.environ.get(name)
    if value is None:
        return default
    return value.strip().lower() in ('1', 'true', 'yes', 'on')


def env_list(name: str, default: str = '') -> list:
    return [v.strip() for v in os.environ.get(name, default).split(',') if v.strip()]
