from __future__ import annotations

from typing import Any

from app.api.deps import CurrentUserContext


def build_trusted_expense_application_context(
    current_user: CurrentUserContext,
    base_context: dict[str, Any] | None = None,
) -> dict[str, Any]:
    context_json = dict(base_context or {})
    context_json.setdefault("session_type", "application")
    context_json.setdefault("entry_source", "workbench_ai_inline")
    context_json.setdefault("document_type", "expense_application")
    context_json.setdefault("application_stage", "expense_application")
    # 身份与权限字段必须覆盖请求体中的同名值。
    context_json.update(
        {
            "tenant_id": current_user.tenant_id,
            "role_codes": current_user.role_codes,
            "is_admin": current_user.is_admin,
            "username": current_user.username,
            "name": current_user.name,
            "department_name": current_user.department_name,
            "position": current_user.position,
            "grade": current_user.grade,
            "employee_no": current_user.employee_no,
            "manager_name": current_user.manager_name,
        }
    )
    return context_json
