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

class LaboratorioController extends BaseController {
  constructor() {
    super(Laboratorio, 'Laboratorio', ['Name', 'Detail']);
  }
  // Obtener por tipo
  getByTipo = async (req, res, next) => {
    try {
      const { tipoId } = req.params;
      
      const data = await Laboratorio.findAll({
        where: { TipoId: tipoId },
        include: [
          {
            model: ItemLaboratorio,
            as: 'items'
          }
        ]
      });

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

module.exports = new LaboratorioController();