import { Injectable } from '@nestjs/common';
import { CommandGuardPort } from '../../domain/ports/outbound/command-guard.port';
import { CommandRiskLevel } from '../../domain/value-objects/command-risk-level.vo';
import { CommandRiskClassifier } from '../../domain/services/command-risk-classifier';

@Injectable()
export class CommandGuardService implements CommandGuardPort {
  private readonly classifier = new CommandRiskClassifier();

  classifyCommand(command: string): CommandRiskLevel {
    return this.classifier.classify(command);
  }

  shouldBlock(command: string): boolean {
    return this.classifier.classify(command) === CommandRiskLevel.FORBIDDEN;
  }

  getBlockReason(command: string): string | null {
    if (this.shouldBlock(command)) {
      return `Command "${command}" is classified as FORBIDDEN and has been blocked`;
    }
    return null;
  }
}
