from __future__ import annotations

from typing import Annotated

from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session

from app.api.deps import CurrentUserContext, get_current_user, get_db
from app.schemas.approval_workbench import ApprovalWorkbenchListRead
from app.services.approval_workbench import ApprovalWorkbenchService

router = APIRouter(prefix="/approval-workbench")
DbSession = Annotated[Session, Depends(get_db)]
CurrentUser = Annotated[CurrentUserContext, Depends(get_current_user)]


@router.get(
    "/items",
    response_model=ApprovalWorkbenchListRead,
    summary="查询当前用户的例外审批优先队列",
    description=(
        "复用现有审批权限范围，按风险、预算、金额、等待时长和材料完整度排序；"
        "AI 建议仅供人工复核，不执行自动审批。"
    ),
)
def list_approval_workbench_items(
    db: DbSession,
    current_user: CurrentUser,
    limit: Annotated[int, Query(ge=1, le=200)] = 100,
) -> ApprovalWorkbenchListRead:
    return ApprovalWorkbenchService(db).list_items(current_user, limit=limit)
