# ============================================================
# Configuration — environment variables with defaults
# ============================================================
import os
from dotenv import load_dotenv

load_dotenv()


# -------------------- Database --------------------
def get_db_url() -> str:
    return os.getenv("DATABASE_URL", "mysql+pymysql://root:1234567890@192.168.50.139:3306/erp")


# -------------------- CORS --------------------
def get_cors_origins() -> list[str]:
    origins = os.getenv("CORS_ORIGINS", "http://localhost:3000")
    return [o.strip() for o in origins.split(",") if o.strip()]


# -------------------- SMTP --------------------
def get_smtp_config() -> dict:
    return {
        "host": os.getenv("SMTP_HOST", "smtp.example.com"),
        "port": int(os.getenv("SMTP_PORT", "587")),
        "user": os.getenv("SMTP_USER", ""),
        "password": os.getenv("SMTP_PASSWORD", ""),
        "from_name": os.getenv("SMTP_FROM_NAME", "ERP System"),
        "from_email": os.getenv("SMTP_FROM_EMAIL", "noreply@example.com"),
        "use_tls": os.getenv("SMTP_USE_TLS", "true").lower() in ("true", "1", "yes"),
    }


# -------------------- Telegram --------------------
def get_telegram_config() -> dict:
    return {
        "bot_token": os.getenv("TELEGRAM_BOT_TOKEN", ""),
        "chat_id": os.getenv("TELEGRAM_CHAT_ID", ""),
    }


# -------------------- AI --------------------
def get_ai_config() -> dict:
    return {
        "model": os.getenv("AI_MODEL", "gpt-4o"),
        "api_key": os.getenv("AI_API_KEY", ""),
    }