const express = require('express');
const router = express.Router();
const {
  getLivestockPolicies,
  createLivestockPolicy,
  getLivestockPolicyById,
  updateLivestockPolicy,
  updateLivestockPolicyStatus,
  deleteLivestockPolicy,
  getLivestockPolicyStats,
  exportToExcel
} = require('../controllers/livestockPolicyController');
const { jwtAuth, checkPermission } = require('../middleware/auth');

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

// 获取生资保单统计
router.get('/stats', jwtAuth, checkPermission('insurance:policy', 'view'), getLivestockPolicyStats);

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

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

// 创建生资保单
router.post('/', jwtAuth, checkPermission('insurance:policy', 'create'), createLivestockPolicy);

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

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

// 删除生资保单
router.delete('/:id', jwtAuth, checkPermission('insurance:policy', 'delete'), deleteLivestockPolicy);

module.exports = router;