// Infinite-Layer Identity Engine (ILIE) API Routes

import { Router } from 'express';
import { ilieService } from './ilie.service';

const router = Router();

/**
 * @swagger
 * /api/v1/ilie/identities:
 *   post:
 *     summary: Create infinite-layer identity
 */
router.post('/identities', async (req, res, next) => {
  try {
    const result = await ilieService.createInfiniteIdentity(req.body);
    res.status(201).json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/ilie/identities/:identityId:
 *   get:
 *     summary: Get infinite-layer identity
 */
router.get('/identities/:identityId', async (req, res, next) => {
  try {
    const identity = await ilieService.getInfiniteIdentity(req.params.identityId);
    if (!identity) {
      return res.status(404).json({ error: 'Identity not found' });
    }
    res.json(identity);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/ilie/identities/:identityId/drift:
 *   get:
 *     summary: Measure identity drift
 */
router.get('/identities/:identityId/drift', async (req, res, next) => {
  try {
    const result = await ilieService.measureIdentityDrift(req.params.identityId);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/ilie/identities/:identityId/correct:
 *   post:
 *     summary: Correct identity drift
 */
router.post('/identities/:identityId/correct', async (req, res, next) => {
  try {
    const result = await ilieService.correctIdentityDrift(req.params.identityId);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/ilie/identities/:identityId/layers:
 *   post:
 *     summary: Add identity layer
 */
router.post('/identities/:identityId/layers', async (req, res, next) => {
  try {
    const result = await ilieService.addIdentityLayer(req.params.identityId, req.body);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/ilie/identities/:identityId/align:
 *   post:
 *     summary: Align identity layers
 */
router.post('/identities/:identityId/align', async (req, res, next) => {
  try {
    const result = await ilieService.alignIdentityLayers(req.params.identityId);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

export default router;

