const BaseController = require('./base.controller');
const { ItemCartilla, Cartilla } = require('../models');

class ItemCartillaController extends BaseController {
  constructor() {
    super(ItemCartilla, 'ItemCartilla', []);
  }

  // Obtener por cartilla
  getByCartilla = async (req, res, next) => {
    try {
      const { cartillaId } = req.params;
      
      const data = await ItemCartilla.findAll({
        where: { CartillaId: cartillaId },
        order: [['SessionNumber', 'ASC']]
      });

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

module.exports = new ItemCartillaController();