// Sovereign AI Risk Engine (SARE) - API Routes

import { Router } from 'express';
import { sareService } from './sare.service';

const router = Router();

/**
 * @swagger
 * tags:
 *   name: Risk Analysis
 *   description: Sovereign AI Risk Engine (SARE)
 */

/**
 * @swagger
 * /api/sare/analyze:
 *   post:
 *     summary: Perform comprehensive risk analysis
 *     description: Analyze risks using the Sovereign AI Risk Engine
 *     tags: [Risk Analysis]
 *     security:
 *       - SovereignToken: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *     responses:
 *       200:
 *         description: Risk analysis completed
 */
router.post('/analyze', async (req, res) => {
  try {
    const inputs = req.body;
    const outputs = await sareService.analyzeRisks(inputs);

    res.json(outputs);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/sare/liquidity-shocks
 * Analyze liquidity shocks (LSA)
 */
router.post('/liquidity-shocks', async (req, res) => {
  try {
    const inputs = req.body;
    const outputs = await sareService.analyzeLiquidityShocks(inputs);

    res.json(outputs);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/sare/fx-collapse
 * Analyze FX collapse probability (FXCP)
 */
router.post('/fx-collapse', async (req, res) => {
  try {
    const inputs = req.body;
    const outputs = await sareService.analyzeFXCollapse(inputs);

    res.json(outputs);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/sare/cbdc-health
 * Analyze CBDC network health (CNHE)
 */
router.post('/cbdc-health', async (req, res) => {
  try {
    const inputs = req.body;
    const outputs = await sareService.analyzeCBDCHealth(inputs);

    res.json(outputs);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/sare/commodity-stress
 * Analyze commodity stress (CSM)
 */
router.post('/commodity-stress', async (req, res) => {
  try {
    const inputs = req.body;
    const outputs = await sareService.analyzeCommodityStress(inputs);

    res.json(outputs);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/sare/actions
 * Generate system actions based on risk outputs
 */
router.post('/actions', async (req, res) => {
  try {
    const outputs = req.body;
    const actions = await sareService.generateSystemActions(outputs);

    res.json(actions);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

export default router;

