// GPN API Routes

import { Router } from 'express';
import { gpnSovereignAccessService } from './gpn-sovereign-access.service';
import { gpnSwitchingService } from './gpn-switching.service';
import { gpnFinalityService } from './gpn-finality.service';
import { gpnMessageHandlerService } from './gpn-message-handler.service';

const router = Router();

/**
 * @swagger
 * /api/v1/gpn/authenticate:
 *   post:
 *     summary: Authenticate sovereign node (Layer 1)
 */
router.post('/authenticate', async (req, res, next) => {
  try {
    const result = await gpnSovereignAccessService.authenticateSovereignNode(req.body);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/gpn/route:
 *   post:
 *     summary: Route payment (Layer 2)
 */
router.post('/route', async (req, res, next) => {
  try {
    const route = await gpnSwitchingService.routePayment(req.body);
    res.json(route);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/gpn/finality:
 *   post:
 *     summary: Verify finality (Layer 3)
 */
router.post('/finality', async (req, res, next) => {
  try {
    const result = await gpnFinalityService.verifyFinality(req.body);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/gpn/hash-lock:
 *   post:
 *     summary: Create hash-lock
 */
router.post('/hash-lock', async (req, res, next) => {
  try {
    const hashLock = await gpnFinalityService.createHashLock(req.body.paymentId);
    res.json({ hashLock });
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/gpn/message/pacs008:
 *   post:
 *     summary: Process PACS.008 message
 */
router.post('/message/pacs008', async (req, res, next) => {
  try {
    const result = await gpnMessageHandlerService.processPacs008(req.body.message, req.body.sovereignBankId);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

export default router;

