import os
from dataclasses import dataclass


@dataclass(frozen=True)
class AppConfig:
    api_key: str
    api_url: str
    model: str
    database_url: str
    history_table_name: str
    default_session_id: str


def load_config() -> AppConfig:
    api_key = os.getenv("API_KEY")
    if not api_key:
        raise ValueError("API_KEY is not set in environment variables.")

    return AppConfig(
        api_key=api_key,
        api_url=os.getenv(
            "API_URL",
            "https://dashscope.aliyuncs.com/compatible-mode/v1",
        ),
        model=os.getenv("MODEL", "qwen3.6-plus"),
        database_url=os.getenv("DATABASE_URL", "mysql+pymysql://root:1234@localhost:3306/mydb"),
        history_table_name=os.getenv("HISTORY_TABLE_NAME", "chat_history"),
        default_session_id=os.getenv("SESSION_ID", "user_001"),
    )
