// SSTM API Routes

import { Router } from 'express';
import { threatClassificationService } from './threat-classification.service';
import { coordinatedThreatDetectionService } from './coordinated-threat-detection.service';
import { threatMitigationService } from './threat-mitigation.service';

const router = Router();

router.post('/threats', async (req, res, next) => {
  try {
    const category = await threatClassificationService.classifyThreat(
      req.body.threatType,
      req.body.severity,
      req.body.affectedBanks
    );
    const threat = await threatClassificationService.createThreat(
      category,
      req.body.threatType,
      req.body.severity,
      req.body.affectedBanks,
      req.body.description
    );
    res.status(201).json(threat);
  } catch (error) {
      return next(error);
  }
});

router.post('/patterns', async (req, res, next) => {
  try {
    const pattern = await coordinatedThreatDetectionService.detectCoordinatedPattern(
      req.body.threatId,
      req.body.patternType,
      req.body.affectedBanks,
      req.body.attackVector
    );
    res.status(201).json(pattern);
  } catch (error) {
      return next(error);
  }
});

router.post('/mitigations', async (req, res, next) => {
  try {
    const mitigation = await threatMitigationService.createMitigation(
      req.body.threatId,
      req.body.incidentId,
      req.body.mitigationType,
      req.body.action,
      req.body.affectedEntities
    );
    res.status(201).json(mitigation);
  } catch (error) {
      return next(error);
  }
});

export default router;

