"""
配置加载

从项目根目录的 config.json 读取配置，返回结构化的配置字典。
"""

import json
from pathlib import Path

_CONFIG_PATH = Path(__file__).parent.parent / "config.json"


def load_config() -> dict:
    """加载并合并配置，缺失字段使用默认值"""
    raw = {}
    if _CONFIG_PATH.exists():
        with open(_CONFIG_PATH, encoding="utf-8") as f:
            raw = json.load(f)

    project_root = _CONFIG_PATH.parent

    return {
        "sso_login_url": raw.get("sso_login_url", "https://tyrz.fynu.edu.cn/sso/login"),
        "portal_url": raw.get("portal_url", "https://tyrz.fynu.edu.cn/oshall"),
        "reimburse_url": raw.get("reimburse_url", "http://210.45.32.214:8081"),
        "reimburse_page": raw.get("reimburse_page", "/expen/common/common?v=4.0"),
        "username": raw.get("username", ""),
        "password": raw.get("password", ""),
        "default_name": raw.get("default_name", ""),
        "default_card_no": raw.get("default_card_no", ""),
        "default_person_id": raw.get("default_person_id", ""),
        "attachment_dir": project_root / "attachments",
    }