'use strict';

const express = require('express');
const router  = express.Router();
const svc     = require('../services/pagosService');

// GET /api/pagos?ini=2026-03-01&fin=2026-03-05
// GET /api/pagos?idturno=123
router.get('/', async (req, res, next) => {
  try {
    const { ini, fin, idturno } = req.query;
    if (!idturno && (!ini || !fin)) {
      return res.status(400).json({ ok: false, error: 'Se requiere ini+fin o idturno' });
    }
    const data = await svc.getFormasPago({ ini, fin, idturno });
    res.json({ ok: true, data });
  } catch (err) { next(err); }
});

// GET /api/pagos/catalogo
router.get('/catalogo', async (req, res, next) => {
  try {
    const data = await svc.getCatalogoFormasPago();
    res.json({ ok: true, data });
  } catch (err) { next(err); }
});

module.exports = router;
