const express = require('express');
const router = express.Router();
const {
  getLivestockClaims,
  createLivestockClaim,
  getLivestockClaimById,
  reviewLivestockClaim,
  updateLivestockClaimPayment,
  getLivestockClaimStats,
  updateLivestockClaim,
  deleteLivestockClaim,
  exportToExcel
} = require('../controllers/livestockClaimController');
const { authenticateToken, requirePermission } = require('../middleware/auth');

// 测试查询参数端点（无认证）
router.get('/test-params', (req, res) => {
  console.log('🧪 [测试端点] 查询参数测试:');
  console.log('req.url:', req.url);
  console.log('req.originalUrl:', req.originalUrl);
  console.log('req.query:', req.query);
  console.log('req.params:', req.params);
  res.json({
    url: req.url,
    originalUrl: req.originalUrl,
    query: req.query,
    params: req.params
  });
});

// 获取生资理赔列表
router.get('/', authenticateToken, requirePermission('livestock_claim:read'), getLivestockClaims);

// 获取生资理赔统计
router.get('/stats', authenticateToken, requirePermission('livestock_claim:read'), getLivestockClaimStats);

// 导出理赔列表到Excel
router.get('/export', authenticateToken, requirePermission('livestock_claim:read'), exportToExcel);

// 获取单个生资理赔详情
router.get('/:id', authenticateToken, requirePermission('livestock_claim:read'), getLivestockClaimById);

// 创建生资理赔申请
router.post('/', authenticateToken, requirePermission('livestock_claim:create'), createLivestockClaim);

// 更新生资理赔信息
router.put('/:id', authenticateToken, requirePermission('livestock_claim:update'), updateLivestockClaim);

// 删除生资理赔
router.delete('/:id', authenticateToken, requirePermission('livestock_claim:delete'), deleteLivestockClaim);

// 审核生资理赔
router.patch('/:id/review', authenticateToken, requirePermission('livestock_claim:review'), reviewLivestockClaim);

// 更新理赔支付状态
router.patch('/:id/payment', authenticateToken, requirePermission('livestock_claim:payment'), updateLivestockClaimPayment);

module.exports = router;