const swaggerJsdoc = require('swagger-jsdoc');

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'API Sistema Médico',
      version: '1.0.0',
      description: 'API REST para sistema de gestión médica con Node.js, Express y PostgreSQL',
      contact: {
        name: 'Soporte API',
        email: 'soporte@medical.com'
      }
    },
    servers: [
      {
        url: `http://localhost:${process.env.PORT || 3000}`,
        description: 'Servidor de desarrollo'
      },
      {
        url: 'https://api.medical.com',
        description: 'Servidor de producción'
      }
    ],
    components: {
      securitySchemes: {
        bearerAuth: {
          type: 'http',
          scheme: 'bearer',
          bearerFormat: 'JWT',
          description: 'Ingrese el token JWT'
        }
      },
      schemas: {
        Error: {
          type: 'object',
          properties: {
            success: {
              type: 'boolean',
              example: false
            },
            message: {
              type: 'string',
              example: 'Mensaje de error'
            },
            errors: {
              type: 'array',
              items: {
                type: 'object'
              }
            }
          }
        },
        Success: {
          type: 'object',
          properties: {
            success: {
              type: 'boolean',
              example: true
            },
            message: {
              type: 'string',
              example: 'Operación exitosa'
            },
            data: {
              type: 'object'
            }
          }
        },
        Pagination: {
          type: 'object',
          properties: {
            success: {
              type: 'boolean',
              example: true
            },
            data: {
              type: 'array',
              items: {
                type: 'object'
              }
            },
            pagination: {
              type: 'object',
              properties: {
                total: {
                  type: 'integer',
                  example: 100
                },
                page: {
                  type: 'integer',
                  example: 1
                },
                limit: {
                  type: 'integer',
                  example: 10
                },
                totalPages: {
                  type: 'integer',
                  example: 10
                }
              }
            }
          }
        },
        Admin: {
          type: 'object',
          properties: {
            id: {
              type: 'integer',
              example: 1
            },
            Name: {
              type: 'string',
              example: 'Juan'
            },
            LastName: {
              type: 'string',
              example: 'Pérez'
            },
            Phone: {
              type: 'string',
              example: '1234567890'
            },
            Email: {
              type: 'string',
              format: 'email',
              example: 'admin@medical.com'
            },
            Password: {
              type: 'string',
              format: 'password',
              example: 'password123'
            },
            Condition: {
              type: 'string',
              example: 'Activo'
            },
            ConditionMin: {
              type: 'string',
              example: 'A'
            },
            Photo: {
              type: 'string',
              example: 'https://example.com/photo.jpg'
            },
            Code: {
              type: 'string',
              example: 'ADM001'
            }
          },
          required: ['Name', 'LastName', 'Email', 'Password']
        },
        Doctor: {
          type: 'object',
          properties: {
            id: {
              type: 'integer',
              example: 1
            },
            Name: {
              type: 'string',
              example: 'María'
            },
            LastName: {
              type: 'string',
              example: 'García'
            },
            MedicalSchoolNumber: {
              type: 'string',
              example: 'MED12345'
            },
            Email: {
              type: 'string',
              format: 'email',
              example: 'doctor@medical.com'
            },
            Password: {
              type: 'string',
              format: 'password',
              example: 'password123'
            },
            Photo: {
              type: 'string',
              example: 'https://example.com/photo.jpg'
            },
            Code: {
              type: 'string',
              example: 'DOC001'
            },
            Condition: {
              type: 'string',
              example: 'Activo'
            }
          },
          required: ['Name', 'LastName', 'Email', 'Password']
        },
        Cliente: {
          type: 'object',
          properties: {
            id: {
              type: 'integer',
              example: 1
            },
            Name: {
              type: 'string',
              example: 'Carlos'
            },
            LastName: {
              type: 'string',
              example: 'López'
            },
            BirthDate: {
              type: 'string',
              format: 'date',
              example: '1990-01-01'
            },
            Job: {
              type: 'string',
              example: 'Ingeniero'
            },
            Direction: {
              type: 'string',
              example: 'Calle 123'
            },
            Phone: {
              type: 'string',
              example: '1234567890'
            },
            Gender: {
              type: 'string',
              example: 'Masculino'
            },
            CivilStatus: {
              type: 'string',
              example: 'Soltero'
            },
            DocumentNumber: {
              type: 'string',
              example: '12345678'
            },
            Email: {
              type: 'string',
              format: 'email',
              example: 'cliente@email.com'
            },
            Bloodtype: {
              type: 'string',
              example: 'O+'
            }
          },
          required: ['Name', 'LastName', 'DocumentNumber']
        },
        Cita: {
          type: 'object',
          properties: {
            id: {
              type: 'integer',
              example: 1
            },
            Appointment: {
              type: 'string',
              format: 'date-time',
              example: '2024-01-15T10:00:00Z'
            },
            Reason: {
              type: 'string',
              example: 'Consulta general'
            },
            Amount: {
              type: 'string',
              example: '50.00'
            },
            Condition: {
              type: 'string',
              example: 'Programada'
            },
            Type: {
              type: 'string',
              example: 'Consulta'
            },
            AdminId: {
              type: 'integer',
              example: 1
            },
            ClienteId: {
              type: 'integer',
              example: 1
            }
          },
          required: ['AdminId', 'ClienteId']
        },
        Especialidad: {
          type: 'object',
          properties: {
            id: {
              type: 'integer',
              example: 1
            },
            Name: {
              type: 'string',
              example: 'Cardiología'
            },
            Resume: {
              type: 'string',
              example: 'Especialidad en enfermedades del corazón'
            },
            Price: {
              type: 'number',
              format: 'decimal',
              example: 100.00
            },
            Icon: {
              type: 'string',
              example: 'heart-icon.png'
            },
            Image: {
              type: 'string',
              example: 'cardiology.jpg'
            }
          },
          required: ['Name']
        }
      }
    },
    security: [
      {
        bearerAuth: []
      }
    ],
    tags: [
      {
        name: 'Auth',
        description: 'Endpoints de autenticación',
      },
      {
        name: 'Admin',
        description: 'Gestión de administradores'
      },
      {
        name: 'Doctor',
        description: 'Gestión de doctores'
      },
      {
        name: 'Cliente',
        description: 'Gestión de clientes/pacientes'
      },
      {
        name: 'Cita',
        description: 'Gestión de citas médicas'
      },
      {
        name: 'Especialidad',
        description: 'Gestión de especialidades médicas'
      },
      {
        name: 'Especialista',
        description: 'Relación doctor-especialidad'
      },
      {
        name: 'Laboratorio',
        description: 'Gestión de laboratorios'
      },
      {
        name: 'Diagnostico',
        description: 'Gestión de diagnósticos'
      },
      {
        name: 'Empresa',
        description: 'Información de la empresa'
      },
      {
        name: 'Agendamiento',
        description: 'Gestión de agenda'
      },
      {
        name: 'Cartilla',
        description: 'Gestión de cartillas de terapia'
      },
      {
        name: 'Auditoria',
        description: 'Registro de auditoría'
      }
    ]
  },
  apis: ['./src/routes/*.js', './src/controllers/*.js']
};

const swaggerSpec = swaggerJsdoc(options);

module.exports = swaggerSpec;