# =============================================================================
# 企微IT智能服务台 — API 路由汇总
# =============================================================================
# 说明：汇总所有 API 子路由，统一挂载到 FastAPI 应用
# T02 阶段注册所有后端核心服务路由
# =============================================================================

from fastapi import APIRouter

# 导入各子路由模块
from app.api.wecom_callback import router as wecom_router
from app.api.conversations import router as conversations_router
from app.api.messages import router as messages_router
from app.api.agents import router as agents_router
from app.api.quick_replies import router as quick_replies_router
from app.api.h5 import router as h5_router
from app.api.agent_notes import router as agent_notes_router
from app.api.system import router as system_router
from app.api.wingman import router as wingman_router
from app.api.todo_items import router as todo_items_router
from app.api.troubleshooting_templates import router as troubleshooting_templates_router
from app.api.employees import router as employees_router
from app.api.upload import router as upload_router
from app.api.admin import router as admin_router
from app.api.portal import router as portal_router
from app.api.admin_roles import router as admin_roles_router
from app.api.approval import router as approval_router

# 创建 API 路由器
# 所有子路由都会挂载到这个路由器上
api_router = APIRouter()

# --------------------------------------------------------------------------
# 注册所有子路由
# --------------------------------------------------------------------------
# 每个子路由都有对应的 prefix 和 tags，方便 Swagger 文档分类展示
# --------------------------------------------------------------------------

# 企微回调 API
# GET  /api/wecom/callback — 验证URL有效性
# POST /api/wecom/callback — 接收企微推送消息
api_router.include_router(wecom_router, tags=["企微回调"])

# 会话管理 API
# GET    /api/conversations           — 获取会话列表
# GET    /api/conversations/{id}      — 获取会话详情
# POST   /api/conversations/{id}/assign — 坐席接单
# POST   /api/conversations/{id}/resolve — 结单
# POST   /api/conversations/{id}/pin  — 置顶/取消置顶
# POST   /api/conversations/{id}/todo — 代办/取消代办
# POST   /api/conversations/{id}/transfer — 转接
api_router.include_router(conversations_router, tags=["会话管理"])

# 消息管理 API
# GET  /api/conversations/{id}/messages      — 获取消息列表
# POST /api/conversations/{id}/messages      — 坐席发送消息
# GET  /api/conversations/{id}/messages/poll — 轮询新消息
api_router.include_router(messages_router, tags=["消息管理"])

# 坐席管理 API
# POST /api/agents/login    — 坐席登录
# GET  /api/agents/me       — 获取当前坐席信息
# PUT  /api/agents/me/status — 更新坐席状态
# GET  /api/agents          — 获取坐席列表
api_router.include_router(agents_router, tags=["坐席管理"])

# 快速回复模板 API
# GET    /api/quick-replies       — 获取模板列表
# POST   /api/quick-replies       — 创建模板
# PUT    /api/quick-replies/{id}  — 更新模板
# DELETE /api/quick-replies/{id}  — 删除模板
api_router.include_router(quick_replies_router, tags=["快速回复"])

# H5 用户端 API
# POST /api/h5/oauth/callback                           — OAuth2回调
# GET  /api/h5/user                                     — 获取用户信息
# GET  /api/h5/conversations/current                    — 获取当前会话
# POST /api/h5/conversations/current/messages           — 发送消息
# GET  /api/h5/conversations/current/messages/poll      — 轮询新消息
# POST /api/h5/conversations/current/shake              — 摇人
# GET  /api/h5/approval-links                           — 获取审批链接
# GET  /api/h5/software-downloads                       — 获取软件下载
api_router.include_router(h5_router, tags=["H5用户端"])

# 坐席备注 API
# GET    /api/agent-notes/{employee_id} — 获取员工备注
# POST   /api/agent-notes              — 添加备注
# PUT    /api/agent-notes/{id}         — 更新备注
# DELETE /api/agent-notes/{id}         — 删除备注
api_router.include_router(agent_notes_router, tags=["坐席备注"])

# 系统管理 API
# GET /api/system/emergency-mode  — 查询应急模式状态
# PUT /api/system/emergency-mode  — 切换应急模式开关
api_router.include_router(system_router, tags=["系统管理"])

# AI Wingman 智能副驾驶 API
# POST /api/conversations/{id}/wingman/draft   — 生成 AI 草稿回复
# POST /api/conversations/{id}/wingman/summary — 生成会话自动摘要
# POST /api/conversations/{id}/wingman/tags    — 生成自动标签建议
api_router.include_router(wingman_router, tags=["AI Wingman"])

# 待办事项 API
# GET  /api/todo-items            — 获取当前坐席待办列表
# GET  /api/todo-items/{id}       — 获取待办详情
# PUT  /api/todo-items/{id}/status — 更新待办状态
api_router.include_router(todo_items_router, tags=["待办事项"])

# 排查模板 API
# GET    /api/troubleshooting-templates          — 获取排查模板列表
# GET    /api/troubleshooting-templates/{id}     — 获取排查模板详情
# POST   /api/troubleshooting-templates          — 新增模板（管理员）
# PUT    /api/troubleshooting-templates/{id}     — 修改模板（管理员）
# DELETE /api/troubleshooting-templates/{id}     — 删除模板（管理员）
api_router.include_router(troubleshooting_templates_router, tags=["排查模板"])

# 员工管理 API
# PUT /api/employees/{employee_id}/it-level — 更新员工IT技能等级
api_router.include_router(employees_router, tags=["员工管理"])

# 文件上传 API
# POST /api/upload                       — 上传文件（图片/文档）
# GET  /api/media/{year}/{month}/{day}/{filename} — 访问上传的文件
api_router.include_router(upload_router, tags=["文件上传"])

# 管理后台 API
# GET    /api/admin/dashboard/overview              — 仪表盘统计
# GET    /api/admin/configs                          — 获取配置分组
# PUT    /api/admin/configs/{key}                    — 更新配置项
# GET    /api/admin/configs/{key}/history            — 配置变更历史
# GET    /api/admin/agents                           — 坐席列表（管理视图）
# POST   /api/admin/agents                           — 添加坐席
# PUT    /api/admin/agents/{id}                      — 编辑坐席
# DELETE /api/admin/agents/{id}                      — 移除坐席
# GET    /api/admin/integrations                     — 集成系统列表
# PUT    /api/admin/integrations/{id}                — 更新集成配置
# GET    /api/admin/quick-replies/pending            — 待审核快速回复
# PUT    /api/admin/quick-replies/{id}/review        — 审核快速回复
# GET    /api/admin/assignment-mode                   — 获取分配模式
# PUT    /api/admin/assignment-mode                   — 切换分配模式
# GET    /api/admin/monitor/sessions                  — 会话监控
# GET    /api/admin/search                            — 全局搜索
api_router.include_router(admin_router, tags=["管理后台"])

# Portal 统一入口 API
# GET  /api/portal/roles           — 获取当前用户角色信息
# POST /api/portal/switch-role     — 切换当前角色
# GET  /api/portal/entry/{role}    — 获取角色对应的入口 URL
api_router.include_router(portal_router, tags=["统一入口"])

# 管理后台角色管理 API
# GET    /api/admin/roles                     — 获取所有角色
# POST   /api/admin/roles/assign              — 分配角色
# POST   /api/admin/roles/revoke              — 撤销角色
# GET    /api/admin/roles/mapping-rules       — 获取映射规则
# POST   /api/admin/roles/mapping-rules       — 创建映射规则
# DELETE /api/admin/roles/mapping-rules/{id}  — 删除映射规则
api_router.include_router(admin_roles_router, tags=["角色管理"])

# 审批流程 API
# GET  /api/approval/templates           — 获取审批模板列表
# GET  /api/approval/templates/{id}    — 获取审批模板详情
# POST /api/approval/jump              — 生成跳转审批链接
# POST /api/approval/submit            — API提交审批
# GET  /api/approval/keywords         — 获取审批关键词
api_router.include_router(approval_router, tags=["审批流程"])
