const express = require('express');
const router = express.Router();
const { authMiddleware } = require('../middleware/auth');
const {
  getLoanProducts,
  getLoanProductById,
  createLoanProduct,
  updateLoanProduct,
  deleteLoanProduct,
  getLoanProductStats,
  batchUpdateStatus,
  batchDelete
} = require('../controllers/loanProductController');

// 应用认证中间件到所有路由
router.use(authMiddleware);

// 获取贷款商品列表
router.get('/', getLoanProducts);

// 获取贷款商品统计信息
router.get('/stats', getLoanProductStats);

// 根据ID获取贷款商品详情
router.get('/:id', getLoanProductById);

// 创建贷款商品
router.post('/', createLoanProduct);

// 更新贷款商品
router.put('/:id', updateLoanProduct);

// 批量更新在售状态
router.put('/batch/status', batchUpdateStatus);

// 删除贷款商品
router.delete('/:id', deleteLoanProduct);

// 批量删除贷款商品
router.delete('/batch/delete', batchDelete);

module.exports = router;