// Trans-Causal Monetary Protocol (TCMP) API Routes

import { Router } from 'express';
import { tcmpService } from './tcmp.service';

const router = Router();

/**
 * @swagger
 * /api/v1/tcmp/transactions:
 *   post:
 *     summary: Create trans-causal transaction
 */
router.post('/transactions', async (req, res, next) => {
  try {
    const result = await tcmpService.createTransCausalTransaction(req.body);
    res.status(201).json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/tcmp/transactions/:tcxId:
 *   get:
 *     summary: Get trans-causal transaction
 */
router.get('/transactions/:tcxId', async (req, res, next) => {
  try {
    const transaction = await tcmpService.getTransCausalTransaction(req.params.tcxId);
    if (!transaction) {
      return res.status(404).json({ error: 'Transaction not found' });
    }
    res.json(transaction);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/tcmp/transactions/:tcxId/resolve:
 *   post:
 *     summary: Resolve deferred transaction
 */
router.post('/transactions/:tcxId/resolve', async (req, res, next) => {
  try {
    const result = await tcmpService.resolveTransaction(req.params.tcxId, req.body.resolutionResult);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

export default router;

