import { Router } from "express";
import {
  webHook,
  sypagoWebhook,
  refreshTokenBancamiga,
} from "../controllers/bancamigaController";
import { authorizeModules, verifyToken } from "../middlewares/authJwt";
import { validateBancamigaWebhook } from "../middlewares/webhookValidator";

const bancamigaRouter = Router();

/**
 * @swagger
 * tags:
 *   name: Bancamiga
 *   description: Integración Bancamiga y Sypago
 */

/**
 * @swagger
 * /bancamiga/sypago-webhook:
 *   post:
 *     operationId: sypagoWebhook
 *     tags: [Bancamiga]
 *     summary: Webhook Sypago
 *     description: Recibe notificaciones de Sypago (cobro de membresía se procesa en el flujo de registro)
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             description: Payload del webhook Sypago
 *             properties:
 *               transaction_id:
 *                 type: string
 *                 description: ID de la transacción en Sypago
 *               status:
 *                 type: string
 *                 description: Estado del cobro
 *               internal_id:
 *                 type: string
 *               amount:
 *                 type: number
 *               group_id:
 *                 type: string
 *                 description: Ej. PASTAMEMBRESIA
 *           example:
 *             transaction_id: "TXN-12345"
 *             status: "completed"
 *             internal_id: "507f1f77bcf86cd799439011"
 *             amount: 10.50
 *             group_id: "PASTAMEMBRESIA"
 *     responses:
 *       200:
 *         description: Webhook procesado correctamente
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               required: [Code, message]
 *               properties:
 *                 Code:
 *                   type: number
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "Webhook procesado correctamente"
 *             example:
 *               Code: 200
 *               message: "Webhook procesado correctamente"
 *       500:
 *         description: Error al procesar el webhook
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 Code:
 *                   type: number
 *                   example: 500
 *                 message:
 *                   type: string
 *                   example: "Error al procesar el webhook"
 */
bancamigaRouter.post("/sypago-webhook", sypagoWebhook);

bancamigaRouter.post("/refresh-token", refreshTokenBancamiga);

bancamigaRouter.use(verifyToken, authorizeModules("webhook"));

bancamigaRouter.post("/webhook", webHook);

export default bancamigaRouter;
