// DBIS International Arbitration Statutes (DIAS) - API Routes

import { Router } from 'express';
import { diasService } from './dias.service';
import { ArbitrationCaseType } from './types';

const router = Router();

/**
 * @swagger
 * tags:
 *   name: Arbitration
 *   description: DBIS International Arbitration Statutes (DIAS)
 */

/**
 * @swagger
 * /api/dias/submit:
 *   post:
 *     summary: Submit a new arbitration case
 *     description: Submit a dispute for international arbitration under DIAS
 *     tags: [Arbitration]
 *     security:
 *       - SovereignToken: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - caseType
 *               - parties
 *             properties:
 *               caseType:
 *                 type: string
 *               parties:
 *                 type: array
 *     responses:
 *       200:
 *         description: Case submitted successfully
 */
router.post('/submit', async (req, res) => {
  try {
    const case_ = await diasService.submitCase(req.body);

    res.json(case_);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/dias/:caseId/verify
 * Verify a case (ledger entries and signatures)
 */
router.post('/:caseId/verify', async (req, res) => {
  try {
    const { caseId } = req.params;

    const result = await diasService.verifyCase(caseId);

    res.json(result);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/dias/:caseId/assign-panel
 * Assign arbitration panel
 */
router.post('/:caseId/assign-panel', async (req, res) => {
  try {
    const { caseId } = req.params;

    const panel = await diasService.assignPanel(caseId);

    res.json(panel);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/dias/:caseId/decision
 * Make arbitration decision
 */
router.post('/:caseId/decision', async (req, res) => {
  try {
    const { caseId } = req.params;

    const case_ = await diasService.makeDecision({
      caseId,
      ...req.body,
    });

    res.json(case_);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/dias/:caseId/execute
 * Execute enforcement actions
 */
router.post('/:caseId/execute', async (req, res) => {
  try {
    const { caseId } = req.params;

    const case_ = await diasService.executeEnforcement(caseId);

    res.json(case_);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * POST /api/dias/:caseId/close
 * Close a case
 */
router.post('/:caseId/close', async (req, res) => {
  try {
    const { caseId } = req.params;

    const case_ = await diasService.closeCase(caseId);

    res.json(case_);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

/**
 * GET /api/dias/:caseId
 * Get a case by ID
 */
router.get('/:caseId', async (req, res) => {
  try {
    const { caseId } = req.params;

    const case_ = await diasService.getCase(caseId);

    res.json(case_);
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

export default router;

