const express = require('express');
const router = express.Router();
const { body, validationResult } = require('express-validator');
const authMiddleware = require('../middleware/auth');
const ReportController = require('../controllers/reportController');

// 生成报表
router.post('/generate', 
  authMiddleware,
  [
    body('reportType')
      .notEmpty()
      .withMessage('报表类型不能为空')
      .isIn(['transaction', 'account', 'user'])
      .withMessage('无效的报表类型'),
    body('dateRange')
      .isArray({ min: 2, max: 2 })
      .withMessage('日期范围必须包含开始和结束日期'),
    body('format')
      .notEmpty()
      .withMessage('报表格式不能为空')
      .isIn(['excel', 'pdf', 'csv'])
      .withMessage('无效的报表格式')
  ],
  ReportController.generateReport
);

// 获取报表历史
router.get('/history', 
  authMiddleware,
  ReportController.getReportHistory
);

// 下载报表
router.get('/download/:id', 
  authMiddleware,
  ReportController.downloadReport
);

// 预览报表
router.get('/preview/:id', 
  authMiddleware,
  ReportController.previewReport
);

// 删除报表
router.delete('/:id', 
  authMiddleware,
  ReportController.deleteReport
);

// 获取报表统计
router.get('/stats', 
  authMiddleware,
  ReportController.getReportStats
);

module.exports = router;