// DBIS Economic Entanglement Index (EEI) API Routes

import { Router } from 'express';
import { eeiService } from './eei.service';

const router = Router();

/**
 * @swagger
 * /api/v1/eei/measure:
 *   post:
 *     summary: Measure Economic Entanglement Index
 */
router.post('/measure', async (req, res, next) => {
  try {
    const result = await eeiService.measureEntanglement(req.body);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/eei/latest:
 *   get:
 *     summary: Get latest entanglement measurement
 */
router.get('/latest', async (req, res, next) => {
  try {
    const result = await eeiService.getLatestEntanglement();
    if (!result) {
      return res.status(404).json({ error: 'No measurements found' });
    }
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/eei/history:
 *   get:
 *     summary: Get entanglement history
 */
router.get('/history', async (req, res, next) => {
  try {
    const limit = req.query.limit ? parseInt(req.query.limit as string) : 100;
    const result = await eeiService.getEntanglementHistory(limit);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/eei/:entanglementId:
 *   get:
 *     summary: Get entanglement by ID
 */
router.get('/:entanglementId', async (req, res, next) => {
  try {
    const result = await eeiService.getEntanglement(req.params.entanglementId);
    if (!result) {
      return res.status(404).json({ error: 'Entanglement not found' });
    }
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/eei/trends:
 *   get:
 *     summary: Analyze entanglement trends
 */
router.get('/trends', async (req, res, next) => {
  try {
    const days = req.query.days ? parseInt(req.query.days as string) : 30;
    const result = await eeiService.analyzeEntanglementTrends(days);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

export default router;

