// Superposition-Based Asset Valuation (SBAV) API Routes

import { Router } from 'express';
import { sbavService } from './sbav.service';

const router = Router();

/**
 * @swagger
 * /api/v1/sbav/assets:
 *   post:
 *     summary: Create superposition asset
 */
router.post('/assets', async (req, res, next) => {
  try {
    const result = await sbavService.createSuperpositionAsset(req.body);
    res.status(201).json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/sbav/assets/:assetId:
 *   get:
 *     summary: Get superposition asset
 */
router.get('/assets/:assetId', async (req, res, next) => {
  try {
    const asset = await sbavService.getSuperpositionAsset(req.params.assetId);
    if (!asset) {
      return res.status(404).json({ error: 'Asset not found' });
    }
    res.json(asset);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/sbav/assets/:assetId/value:
 *   get:
 *     summary: Calculate superposed value
 */
router.get('/assets/:assetId/value', async (req, res, next) => {
  try {
    const result = await sbavService.calculateSuperposedValue(req.params.assetId);
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/sbav/assets/:assetId/collapse:
 *   post:
 *     summary: Collapse asset to single state
 */
router.post('/assets/:assetId/collapse', async (req, res, next) => {
  try {
    const result = await sbavService.collapseAsset({
      assetId: req.params.assetId,
      ...req.body,
    });
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/sbav/assets/:assetId/probabilities:
 *   put:
 *     summary: Update state probabilities
 */
router.put('/assets/:assetId/probabilities', async (req, res, next) => {
  try {
    const result = await sbavService.updateStateProbabilities(
      req.params.assetId,
      req.body.stateProbabilities
    );
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/sbav/assets/:assetId/states:
 *   post:
 *     summary: Add new superposition state
 */
router.post('/assets/:assetId/states', async (req, res, next) => {
  try {
    const result = await sbavService.addSuperpositionState(
      req.params.assetId,
      req.body
    );
    res.json(result);
  } catch (error) {
      return next(error);
  }
});

export default router;

