// Threat Mitigation Service

import prisma from '@/shared/database/prisma';
import { v4 as uuidv4 } from 'uuid';


export class ThreatMitigationService {
  /**
   * Create threat mitigation
   */
  async createMitigation(
    threatId: string | undefined,
    incidentId: string | undefined,
    mitigationType: string,
    action: string,
    affectedEntities: string[]
  ) {
    const mitigationId = `MITIGATION-${uuidv4()}`;

    return await prisma.threat_mitigations.create({
      data: {
        mitigationId,
        threatId,
        incidentId,
        mitigationType,
        action,
        affectedEntities,
        status: 'pending',
      },
    });
  }

  /**
   * Execute mitigation
   */
  async executeMitigation(mitigationId: string) {
    return await prisma.threat_mitigations.update({
      where: { mitigationId },
      data: {
        status: 'executing',
      },
    });
  }

  /**
   * Complete mitigation
   */
  async completeMitigation(mitigationId: string) {
    return await prisma.threat_mitigations.update({
      where: { mitigationId },
      data: {
        status: 'completed',
        completedAt: new Date(),
      },
    });
  }
}

export const threatMitigationService = new ThreatMitigationService();

