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

// 获取保单统计（必须在动态路由之前）
router.get('/stats/overview', jwtAuth, checkPermission('insurance:policy', 'view'),
  policyController.getPolicyStats
);

// 获取保单列表
router.get('/', jwtAuth, checkPermission('insurance:policy', 'view'), 
  policyController.getPolicies
);

// 创建保单
router.post('/', jwtAuth, checkPermission('insurance:policy', 'create'),
  policyController.createPolicy
);

// 导出保单列表到Excel
router.get('/export', jwtAuth, checkPermission('insurance:policy', 'view'), policyController.exportToExcel);

// 获取单个保单详情
router.get('/:id', jwtAuth, checkPermission('insurance:policy', 'view'),
  policyController.getPolicyById
);

// 更新保单
router.put('/:id', jwtAuth, checkPermission('insurance:policy', 'edit'),
  policyController.updatePolicy
);

// 更新保单状态
router.patch('/:id/status', jwtAuth, checkPermission('insurance:policy', 'edit'),
  policyController.updatePolicyStatus
);

// 删除保单
router.delete('/:id', jwtAuth, checkPermission('insurance:policy', 'delete'),
  policyController.deletePolicy
);

module.exports = router;