// Sovereign Holographic Anchor System (SHAS) API Routes

import { Router } from 'express';
import { shasService } from './shas.service';

const router = Router();

/**
 * @swagger
 * /api/v1/shas/anchors:
 *   post:
 *     summary: Create holographic anchor
 */
router.post('/anchors', async (req, res, next) => {
  try {
    const result = await shasService.createHolographicAnchor(req.body);
    res.status(201).json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/shas/anchors/:anchorId:
 *   get:
 *     summary: Get holographic anchor
 */
router.get('/anchors/:anchorId', async (req, res, next) => {
  try {
    const anchor = await shasService.getHolographicAnchor(req.params.anchorId);
    if (!anchor) {
      return res.status(404).json({ error: 'Anchor not found' });
    }
    res.json(anchor);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/shas/anchors/:anchorId/integrity:
 *   post:
 *     summary: Perform integrity check
 */
router.post('/anchors/:anchorId/integrity', async (req, res, next) => {
  try {
    const result = await shasService.performIntegrityCheck(req.params.anchorId);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/shas/anchors/:anchorId/update:
 *   put:
 *     summary: Update anchor state
 */
router.put('/anchors/:anchorId/update', async (req, res, next) => {
  try {
    const result = await shasService.updateAnchorState(req.params.anchorId, req.body);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/shas/anchors/:anchorId/settlements:
 *   post:
 *     summary: Create holographic settlement
 */
router.post('/anchors/:anchorId/settlements', async (req, res, next) => {
  try {
    const result = await shasService.createHolographicSettlement(
      req.params.anchorId,
      req.body.settlementData,
      req.body.settlementType
    );
    res.status(201).json(result);
  } catch (error) {
      return next(error);
  }
});

export default router;

