/**
 * @swagger
 * tags:
 *   name: SolaceNet Limits
 *   description: Limits and velocity controls
 */

import { Router } from 'express';
import { zeroTrustAuthMiddleware } from '@/integration/api-gateway/middleware/auth.middleware';
import { limitsService, CreateLimitRequest, CheckLimitRequest } from './limits.service';

const router = Router();

/**
 * @swagger
 * /api/v1/solacenet/limits:
 *   post:
 *     summary: Create a limit
 *     tags: [SolaceNet Limits]
 *     security:
 *       - SovereignToken: []
 */
router.post('/', zeroTrustAuthMiddleware, async (req, res, next) => {
  try {
    const request = req.body as CreateLimitRequest;
    const limit = await limitsService.createLimit(request);
    res.status(201).json(limit);
  } catch (error) {
    next(error);
  }
});

/**
 * @swagger
 * /api/v1/solacenet/limits/check:
 *   post:
 *     summary: Check if transaction would exceed limits
 *     tags: [SolaceNet Limits]
 *     security:
 *       - SovereignToken: []
 */
router.post('/check', zeroTrustAuthMiddleware, async (req, res, next) => {
  try {
    const request = req.body as CheckLimitRequest;
    const result = await limitsService.checkLimit(request);
    res.json(result);
  } catch (error) {
    next(error);
  }
});

export default router;
