// DCDC API Routes

import { Router } from 'express';
import { cyberThreatIncidentService } from './cyber-threat-incident.service';
import { dcdcStrategicDefenseService } from './dcdc-strategic-defense.service';
import { dcdcOperationalDefenseService } from './dcdc-operational-defense.service';
import { defenseLayersService } from './defense-layers.service';

const router = Router();

router.post('/threats', async (req, res, next) => {
  try {
    const incident = await cyberThreatIncidentService.createThreatIncident(req.body);
    res.status(201).json(incident);
  } catch (error) {
      return next(error);
  }
});

router.get('/threats/:incidentId', async (req, res, next) => {
  try {
    const incident = await cyberThreatIncidentService.getThreatIncident(req.params.incidentId);
    res.json(incident);
  } catch (error) {
      return next(error);
  }
});

router.post('/forecast', async (req, res, next) => {
  try {
    const forecast = await dcdcStrategicDefenseService.generateThreatForecast(
      req.body.threatType,
      req.body.severity,
      req.body.probability,
      req.body.expectedTimeframe,
      req.body.affectedEntities,
      req.body.mitigationRecommendations
    );
    res.json(forecast);
  } catch (error) {
      return next(error);
  }
});

router.post('/quarantine', async (req, res, next) => {
  try {
    const quarantine = await dcdcOperationalDefenseService.quarantineNode(
      req.body.nodeId,
      req.body.reason,
      req.body.quarantineType
    );
    res.json(quarantine);
  } catch (error) {
      return next(error);
  }
});

router.post('/defense-sequence', async (req, res, next) => {
  try {
    const response = await defenseLayersService.executeDefenseSequence(
      req.body.incidentId,
      req.body.threatType,
      req.body.severity,
      req.body.targetNodeId,
      req.body.targetBankId
    );
    res.json(response);
  } catch (error) {
      return next(error);
  }
});

export default router;

