/**
 * OpenAPI 3.0 规范，供 Swagger UI 展示
 */
const PORT = process.env.API_PORT || 3001

module.exports = {
  openapi: '3.0.3',
  info: {
    title: 'US-Iran Military Dashboard API',
    version: '1.0.0',
    description: '美伊军事态势面板后端接口',
  },
  servers: [{ url: `http://localhost:${PORT}`, description: '本地' }],
  paths: {
    '/api/situation': {
      get: {
        summary: '获取态势数据',
        description: '战损、基地、新闻、冲突事件等完整态势',
        tags: ['态势'],
        responses: {
          200: {
            description: '态势 JSON',
            content: { 'application/json': { schema: { type: 'object' } } },
          },
        },
      },
    },
    '/api/news': {
      get: {
        summary: '资讯内容',
        description: '从 news_content 表读取，支持 ?limit=50 分页',
        tags: ['资讯'],
        parameters: [{ in: 'query', name: 'limit', schema: { type: 'integer', default: 50 } }],
        responses: { 200: { description: 'items 数组' } },
      },
    },
    '/api/db/dashboard': {
      get: {
        summary: '数据库面板',
        description: '各表原始数据，供 /db 调试页',
        tags: ['调试'],
        responses: {
          200: {
            description: '各表数据',
            content: { 'application/json': { schema: { type: 'object' } } },
          },
        },
      },
    },
    '/api/visit': {
      post: {
        summary: '来访统计',
        description: '记录 IP，返回当前在看人数和看过人数',
        tags: ['统计'],
        responses: {
          200: {
            description: 'OK',
            content: {
              'application/json': {
                schema: {
                  type: 'object',
                  properties: {
                    viewers: { type: 'number' },
                    cumulative: { type: 'number' },
                  },
                },
              },
            },
          },
        },
      },
    },
    '/api/feedback': {
      post: {
        summary: '提交反馈',
        description: '留言 1–2000 字',
        tags: ['反馈'],
        requestBody: {
          required: true,
          content: {
            'application/json': {
              schema: {
                type: 'object',
                required: ['content'],
                properties: { content: { type: 'string', maxLength: 2000 } },
              },
            },
          },
        },
        responses: {
          200: { description: 'ok: true' },
          400: { description: '内容超长或为空' },
        },
      },
    },
    '/api/health': {
      get: {
        summary: '健康检查',
        tags: ['系统'],
        responses: { 200: { description: 'ok: true' } },
      },
    },
    '/api/crawler/notify': {
      post: {
        summary: '爬虫通知',
        description: '爬虫更新后调用，触发前端推送',
        tags: ['系统'],
        responses: { 200: { description: 'ok' } },
      },
    },
    '/api/stats': {
      get: {
        summary: '统计快照',
        description: 'viewers / cumulative，不写入',
        tags: ['统计'],
        responses: {
          200: {
            content: {
              'application/json': {
                schema: {
                  type: 'object',
                  properties: {
                    viewers: { type: 'number' },
                    cumulative: { type: 'number' },
                  },
                },
              },
            },
          },
        },
      },
    },
    '/api/events': {
      get: {
        summary: '冲突事件',
        description: '冲突事件列表及统计',
        tags: ['态势'],
        responses: { 200: { description: 'events + conflict_stats' } },
      },
    },
  },
  tags: [{ name: '态势' }, { name: '资讯' }, { name: '统计' }, { name: '反馈' }, { name: '调试' }, { name: '系统' }],
}
