const BaseController = require('./base.controller');
const { Analisis, Cita, Laboratorio } = require('../models');

class AnalisisController extends BaseController {
  constructor() {
    super(Analisis, 'Analisis', []);
  }

  // Obtener por cita
  getByCita = async (req, res, next) => {
    try {
      const { citaId } = req.params;
      
      const data = await Analisis.findAll({
        where: { CitaId: citaId },
        include: [
          {
            model: Laboratorio,
            as: 'laboratorio'
          }
        ]
      });

      res.json({
        success: true,
        message: 'Análisis obtenidos exitosamente',
        data
      });
    } catch (error) {
      next(error);
    }
  };

  // Obtener por laboratorio
  getByLaboratorio = async (req, res, next) => {
    try {
      const { laboratorioId } = req.params;
      
      const data = await Analisis.findAll({
        where: { LaboratorioId: laboratorioId },
        include: [
          {
            model: Cita,
            as: 'cita'
          }
        ]
      });

      res.json({
        success: true,
        message: 'Análisis obtenidos exitosamente',
        data
      });
    } catch (error) {
      next(error);
    }
  };
}

module.exports = new AnalisisController();