const express = require('express');
const router = express.Router();
const SupervisoryTaskController = require('../controllers/supervisoryTaskController');
const { jwtAuth, requirePermission } = require('../middleware/auth');

/**
 * @swagger
 * tags:
 *   name: SupervisionTasks
 *   description: 监管任务管理
 */

/**
 * @swagger
 * /api/supervision-tasks/stats:
 *   get:
 *     summary: 获取监管任务统计信息
 *     tags: [SupervisionTasks]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 */
router.get('/stats', jwtAuth, requirePermission('supervision_tasks:read'), SupervisoryTaskController.getStatistics);

/**
 * @swagger
 * /api/supervision-tasks/export:
 *   get:
 *     summary: 导出监管任务列表到Excel
 *     tags: [SupervisionTasks]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: policyNumber
 *         schema:
 *           type: string
 *         description: 保单编号
 *       - in: query
 *         name: customerName
 *         schema:
 *           type: string
 *         description: 客户姓名
 *     responses:
 *       200:
 *         description: 导出成功
 *         content:
 *           application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
 *             schema:
 *               type: string
 *               format: binary
 */
router.get('/export', jwtAuth, requirePermission('supervision_tasks:read'), SupervisoryTaskController.exportToExcel);

/**
 * @swagger
 * /api/supervision-tasks:
 *   get:
 *     summary: 获取监管任务列表
 *     tags: [SupervisionTasks]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: pageSize
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 每页数量
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *           enum: [pending, processing, completed, rejected]
 *         description: 状态筛选
 *       - in: query
 *         name: taskType
 *         schema:
 *           type: string
 *           enum: [new_application, task_guidance, batch_operation]
 *         description: 任务类型筛选
 *       - in: query
 *         name: applicationId
 *         schema:
 *           type: string
 *         description: 申请单号搜索
 *       - in: query
 *         name: policyId
 *         schema:
 *           type: string
 *         description: 保单编号搜索
 *       - in: query
 *         name: customerName
 *         schema:
 *           type: string
 *         description: 客户姓名搜索
 *     responses:
 *       200:
 *         description: 获取成功
 */
router.get('/', jwtAuth, requirePermission('supervision_tasks:read'), SupervisoryTaskController.getList);

/**
 * @swagger
 * /api/supervision-tasks:
 *   post:
 *     summary: 创建监管任务
 *     tags: [SupervisionTasks]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - applicationId
 *               - policyId
 *               - productName
 *               - customerName
 *               - taskType
 *             properties:
 *               applicationId:
 *                 type: string
 *                 description: 申请单号
 *               policyId:
 *                 type: string
 *                 description: 保单编号
 *               productName:
 *                 type: string
 *                 description: 产品名称
 *               insurancePeriod:
 *                 type: string
 *                 description: 保险期间
 *               customerName:
 *                 type: string
 *                 description: 客户姓名
 *               documentType:
 *                 type: string
 *                 description: 证件类型
 *               documentNumber:
 *                 type: string
 *                 description: 证件号码
 *               applicableAmount:
 *                 type: number
 *                 description: 适用金额
 *               taskType:
 *                 type: string
 *                 enum: [new_application, task_guidance, batch_operation]
 *                 description: 任务类型
 *               assignedTo:
 *                 type: integer
 *                 description: 分配给用户ID
 *               priority:
 *                 type: string
 *                 enum: [low, medium, high, urgent]
 *                 description: 优先级
 *               dueDate:
 *                 type: string
 *                 format: date
 *                 description: 截止日期
 *               remarks:
 *                 type: string
 *                 description: 备注
 *     responses:
 *       201:
 *         description: 创建成功
 */
router.post('/', jwtAuth, requirePermission('supervision_tasks:create'), SupervisoryTaskController.create);

/**
 * @swagger
 * /api/supervision-tasks/{id}:
 *   get:
 *     summary: 获取监管任务详情
 *     tags: [SupervisionTasks]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 监管任务ID
 *     responses:
 *       200:
 *         description: 获取成功
 */
router.get('/:id', jwtAuth, requirePermission('supervision_tasks:read'), SupervisoryTaskController.getById);

/**
 * @swagger
 * /api/supervision-tasks/{id}:
 *   put:
 *     summary: 更新监管任务
 *     tags: [SupervisionTasks]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *         description: 任务ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               status:
 *                 type: string
 *                 enum: [pending, processing, completed, rejected]
 *                 description: 状态
 *               assignedTo:
 *                 type: string
 *                 description: 分配给
 *               priority:
 *                 type: string
 *                 enum: [low, medium, high, urgent]
 *                 description: 优先级
 *               notes:
 *                 type: string
 *                 description: 备注
 *     responses:
 *       200:
 *         description: 更新成功
 */
router.put('/:id', jwtAuth, requirePermission('supervision_tasks:update'), SupervisoryTaskController.update);

/**
 * @swagger
 * /api/supervision-tasks/{id}:
 *   delete:
 *     summary: 删除监管任务
 *     tags: [SupervisionTasks]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *         description: 任务ID
 *     responses:
 *       200:
 *         description: 删除成功
 */
router.delete('/:id', jwtAuth, requirePermission('supervision_tasks:delete'), SupervisoryTaskController.delete);

/**
 * @swagger
 * /api/supervision-tasks/batch/operate:
 *   post:
 *     summary: 批量操作监管任务
 *     tags: [SupervisionTasks]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - ids
 *               - operation
 *             properties:
 *               ids:
 *                 type: array
 *                 items:
 *                   type: integer
 *                 description: 监管任务ID数组
 *               operation:
 *                 type: string
 *                 enum: [assign, updateStatus, delete]
 *                 description: 操作类型
 *               data:
 *                 type: object
 *                 description: 操作数据
 *     responses:
 *       200:
 *         description: 操作成功
 */
router.post('/batch/operate', jwtAuth, requirePermission('supervision_tasks:create'), SupervisoryTaskController.bulkCreate);

module.exports = router;