// Multiverse-Consistent FX/SSU Stability Framework API Routes

import { Router } from 'express';
import { multiverseStabilityService } from './multiverse-stability.service';
import { multiverseFxService } from './multiverse-fx.service';
import { multiverseSsuService } from './multiverse-ssu.service';
import { multiverseDivergenceService } from './multiverse-divergence.service';

const router = Router();

/**
 * @swagger
 * /api/v1/multiverse-stability/calculate:
 *   post:
 *     summary: Calculate stability index
 */
router.post('/calculate', async (req, res, next) => {
  try {
    const index = await multiverseStabilityService.calculateStability(req.body);
    res.status(201).json(index);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/multiverse-stability/indices:
 *   get:
 *     summary: Get all stability indices
 */
router.get('/indices', async (req, res, next) => {
  try {
    const indices = await multiverseStabilityService.getAllStabilityIndices();
    res.json(indices);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/multiverse-stability/fx/calculate:
 *   post:
 *     summary: Calculate FX stability
 */
router.post('/fx/calculate', async (req, res, next) => {
  try {
    const { realityLayer, fxData } = req.body;
    const result = await multiverseFxService.calculateFxStability(realityLayer, fxData);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/multiverse-stability/ssu/calculate:
 *   post:
 *     summary: Calculate SSU inertia
 */
router.post('/ssu/calculate', async (req, res, next) => {
  try {
    const { realityLayer, ssuData } = req.body;
    const result = await multiverseSsuService.calculateSsuInertia(realityLayer, ssuData);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/multiverse-stability/divergence/detect:
 *   post:
 *     summary: Detect divergence
 */
router.post('/divergence/detect', async (req, res, next) => {
  try {
    const divergence = await multiverseDivergenceService.detectDivergence(req.body);
    res.status(201).json(divergence);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/multiverse-stability/divergence/unresolved:
 *   get:
 *     summary: Get unresolved divergences
 */
router.get('/divergence/unresolved', async (req, res, next) => {
  try {
    const divergences = await multiverseDivergenceService.getUnresolvedDivergences();
    res.json(divergences);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/multiverse-stability/divergence/statistics:
 *   get:
 *     summary: Get divergence statistics
 */
router.get('/divergence/statistics', async (req, res, next) => {
  try {
    const stats = await multiverseDivergenceService.getDivergenceStatistics();
    res.json(stats);
  } catch (error) {
      return next(error);
  }
});

export default router;

