// Prime-Reality Oversight Engine API Routes

import { Router } from 'express';
import { proeOversightService } from './proe-oversight.service';
import { proeAlignmentService } from './proe-alignment.service';

const router = Router();

/**
 * @swagger
 * /api/v1/proe/detect:
 *   post:
 *     summary: Detect deviation from Prime Reality
 */
router.post('/detect', async (req, res, next) => {
  try {
    const result = await proeOversightService.detectDeviation(req.body);
    res.status(201).json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/proe/deviation/:deviationId:
 *   get:
 *     summary: Get deviation by ID
 */
router.get('/deviation/:deviationId', async (req, res, next) => {
  try {
    const deviation = await proeOversightService.getDeviation(req.params.deviationId);
    if (!deviation) {
      return res.status(404).json({ error: 'Deviation not found' });
    }
    res.json(deviation);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/proe/deviations:
 *   get:
 *     summary: Get all active deviations
 */
router.get('/deviations', async (req, res, next) => {
  try {
    const deviations = await proeOversightService.getActiveDeviations();
    res.json(deviations);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/proe/monitor:
 *   post:
 *     summary: Monitor all realities for deviation
 */
router.post('/monitor', async (req, res, next) => {
  try {
    const { threshold } = req.body;
    const results = await proeOversightService.monitorAllRealities(threshold);
    res.json(results);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/proe/align/:deviationId:
 *   post:
 *     summary: Enforce Prime Reality alignment
 */
router.post('/align/:deviationId', async (req, res, next) => {
  try {
    const result = await proeAlignmentService.enforcePrimeRealityAlignment(req.params.deviationId);
    res.status(201).json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/proe/align/all:
 *   post:
 *     summary: Enforce alignment for all deviations requiring alignment
 */
router.post('/align/all', async (req, res, next) => {
  try {
    const results = await proeAlignmentService.enforceAllAlignments();
    res.json(results);
  } catch (error) {
      return next(error);
  }
});

export default router;

