// Cross-Chain API Routes

import { Router } from 'express';
import { crossChainSettlementService } from './cross-chain-settlement.service';
import { crossChainVerificationService } from './cross-chain-verification.service';
import { crossChainContractService } from './cross-chain-contract.service';

const router = Router();

/**
 * @swagger
 * /api/v1/cross-chain/settlement/execute:
 *   post:
 *     summary: Execute cross-chain settlement
 */
router.post('/settlement/execute', async (req, res, next) => {
  try {
    const settlementId = await crossChainSettlementService.executeCrossChainSettlement(req.body);
    res.json({ settlementId });
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/cross-chain/verify-header:
 *   post:
 *     summary: Verify chain header
 */
router.post('/verify-header', async (req, res, next) => {
  try {
    const { header, settlementId } = req.body;
    const result = await crossChainVerificationService.verifyChainHeader(header, settlementId);
    res.json({ verified: result });
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/cross-chain/chains/supported:
 *   get:
 *     summary: List supported chains
 */
router.get('/chains/supported', async (req, res, next) => {
  try {
    const chains = crossChainSettlementService.getSupportedChainTypes();
    res.json({ chains });
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/cross-chain/commit:
 *   post:
 *     summary: Create cross-chain commitment
 */
router.post('/commit', async (req, res, next) => {
  try {
    const { settlementId, chainId, commitmentType } = req.body;
    const result = await crossChainContractService.commitToChain(settlementId, chainId, commitmentType);
    res.json({ success: result });
  } catch (error) {
      return next(error);
  }
});

export default router;

