/**
 * API文档路由
 * @file api-docs.js
 * @description 提供Swagger API文档访问
 */

const express = require('express');
const swaggerUi = require('swagger-ui-express');
const swaggerSpecs = require('../swagger-config');

const router = express.Router();

// Swagger UI配置
const swaggerUiOptions = {
  customCss: '.swagger-ui .topbar { display: none }',
  customSiteTitle: '智能预警系统 API 文档',
  swaggerOptions: {
    docExpansion: 'none',
    defaultModelsExpandDepth: 2,
    defaultModelExpandDepth: 2,
    displayRequestDuration: true,
    filter: true,
    showExtensions: true,
    showCommonExtensions: true
  }
};

// 提供JSON格式的API规范
router.get('/swagger.json', (req, res) => {
  res.setHeader('Content-Type', 'application/json');
  res.send(swaggerSpecs);
});

// 提供Swagger UI界面
router.use('/', swaggerUi.serve);
router.get('/', swaggerUi.setup(swaggerSpecs, swaggerUiOptions));

module.exports = router;
