const swaggerJsdoc = require('swagger-jsdoc')

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: '结伴客API文档',
      version: '1.0.0',
      description: '结伴客小程序后端API接口文档'
    },
    servers: [
      {
        url: 'https://admin.jiebanke.com/api/v1',
        description: '开发环境服务器'
      },
      {
        url: 'https://webapi.jiebanke.com/api/v1',
        description: '生产环境服务器'
      }
    ],
    components: {
      securitySchemes: {
        bearerAuth: {
          type: 'http',
          scheme: 'bearer',
          bearerFormat: 'JWT'
        }
      },
      schemas: {
        User: {
          type: 'object',
          properties: {
            id: {
              type: 'integer',
              description: '用户ID'
            },
            openid: {
              type: 'string',
              description: '微信openid'
            },
            username: {
              type: 'string',
              description: '用户名'
            },
            nickname: {
              type: 'string',
              description: '昵称'
            },
            avatar: {
              type: 'string',
              description: '头像URL'
            },
            gender: {
              type: 'string',
              enum: ['male', 'female', 'other'],
              description: '性别'
            },
            birthday: {
              type: 'string',
              format: 'date',
              description: '生日'
            },
            phone: {
              type: 'string',
              description: '手机号'
            },
            email: {
              type: 'string',
              description: '邮箱'
            },
            status: {
              type: 'string',
              enum: ['active', 'inactive', 'banned'],
              description: '用户状态'
            },
            level: {
              type: 'integer',
              description: '用户等级'
            },
            points: {
              type: 'integer',
              description: '用户积分'
            },
            created_at: {
              type: 'string',
              format: 'date-time',
              description: '创建时间'
            },
            updated_at: {
              type: 'string',
              format: 'date-time',
              description: '更新时间'
            }
          }
        },
        ApiResponse: {
          type: 'object',
          properties: {
            success: {
              type: 'boolean'
            },
            data: {
              type: 'object'
            },
            message: {
              type: 'string'
            },
            timestamp: {
              type: 'string',
              format: 'date-time'
            }
          }
        }
      }
    }
  },
  apis: ['src/routes/*.js', 'src/controllers/*.js']
}

const swaggerSpec = swaggerJsdoc(options)

module.exports = swaggerSpec