const express = require('express');
const router = express.Router();
const insuranceController = require('../controllers/insuranceController');
const { jwtAuth, checkPermission } = require('../middleware/auth');

// 获取保险申请列表
router.get('/applications', jwtAuth, checkPermission('insurance', 'read'), 
  insuranceController.getApplications
);

// 获取保险申请统计（必须在 :id 路由之前）
router.get('/applications-stats', jwtAuth, checkPermission('insurance', 'read'),
  insuranceController.getApplicationStats
);

// 导出保险申请数据（必须在 :id 路由之前）
router.get('/applications/export', jwtAuth, checkPermission('insurance', 'read'),
  insuranceController.exportApplications
);

// 创建保险申请
router.post('/applications', jwtAuth, checkPermission('insurance', 'create'),
  insuranceController.createApplication
);

// 获取单个保险申请详情
router.get('/applications/:id', jwtAuth, checkPermission('insurance', 'read'),
  insuranceController.getApplicationById
);

// 更新保险申请
router.put('/applications/:id', jwtAuth, checkPermission('insurance', 'update'),
  insuranceController.updateApplication
);

// 审核保险申请
router.patch('/applications/:id/review', jwtAuth, checkPermission('insurance', 'review'),
  insuranceController.reviewApplication
);

// 删除保险申请
router.delete('/applications/:id', jwtAuth, checkPermission('insurance', 'delete'),
  insuranceController.deleteApplication
);

// 获取参保类型选项
router.get('/categories', jwtAuth, checkPermission('insurance', 'read'),
  insuranceController.getInsuranceCategories
);

module.exports = router;