/**
 * 仪表盘路由
 * @file dashboard.js
 * @description 仪表盘相关的路由定义
 */
const express = require('express');
const dashboardController = require('../controllers/dashboardController');
const { authMiddleware, tellerMiddleware } = require('../middleware/auth');

const router = express.Router();

// 所有路由都需要认证
router.use(authMiddleware);

/**
 * @swagger
 * /api/dashboard:
 *   get:
 *     summary: 获取仪表盘统计数据
 *     tags: [仪表盘]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   type: object
 *                   properties:
 *                     overview:
 *                       type: object
 *                       properties:
 *                         totalUsers:
 *                           type: integer
 *                         totalAccounts:
 *                           type: integer
 *                         totalTransactions:
 *                           type: integer
 *                         totalBalance:
 *                           type: integer
 *                         activeUsers:
 *                           type: integer
 *                         activeAccounts:
 *                           type: integer
 *                     today:
 *                       type: object
 *                       properties:
 *                         transactionCount:
 *                           type: integer
 *                         transactionAmount:
 *                           type: integer
 *                     accountTypes:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           type:
 *                             type: string
 *                           count:
 *                             type: integer
 *                           totalBalance:
 *                             type: integer
 *                     trends:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           date:
 *                             type: string
 *                           count:
 *                             type: integer
 *                           totalAmount:
 *                             type: integer
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务器内部错误
 */
router.get('/', tellerMiddleware, dashboardController.getDashboardStats);

/**
 * @swagger
 * /api/dashboard/charts:
 *   get:
 *     summary: 获取图表数据
 *     tags: [仪表盘]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: type
 *         schema:
 *           type: string
 *           enum: [transaction_trend, account_distribution, user_growth, balance_trend]
 *         description: 图表类型
 *       - in: query
 *         name: period
 *         schema:
 *           type: string
 *           enum: [1d, 7d, 30d, 90d]
 *           default: 7d
 *         description: 时间周期
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   type: object
 *                   properties:
 *                     type:
 *                       type: string
 *                     data:
 *                       type: array
 *       400:
 *         description: 请求参数错误
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务器内部错误
 */
router.get('/charts', tellerMiddleware, dashboardController.getChartData);

/**
 * @swagger
 * /api/dashboard/recent-transactions:
 *   get:
 *     summary: 获取最近交易记录
 *     tags: [仪表盘]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 返回记录数量
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务器内部错误
 */
router.get('/recent-transactions', tellerMiddleware, dashboardController.getRecentTransactions);

module.exports = router;
