import { BaseVerificationStrategy } from "./base-verification.strategy";
import type { VerificationContext, StrategyResult, VerificationIssue } from "../interfaces";

export class FileChangeStrategy extends BaseVerificationStrategy {
  name = "file-change";

  verify(context: VerificationContext): Promise<StrategyResult> {
    const issues: VerificationIssue[] = [];

    // Check if files were changed
    if (context.filesChanged.length === 0) {
      issues.push({
        type: "missing-files",
        severity: "error",
        message: "No files were changed",
      });
    }

    // Check for TODO comments (error - incomplete work)
    const todoPattern = /TODO:/gi;
    const todoMatches = this.extractEvidence(context.outputLogs, todoPattern);
    if (todoMatches.length > 0) {
      issues.push({
        type: "incomplete-implementation",
        severity: "error",
        message: `Found ${todoMatches.length.toString()} TODO comment(s)`,
        evidence: todoMatches.join("\n"),
      });
    }

    // Check for FIXME comments (error - broken code)
    const fixmePattern = /FIXME:/gi;
    const fixmeMatches = this.extractEvidence(context.outputLogs, fixmePattern);
    if (fixmeMatches.length > 0) {
      issues.push({
        type: "incomplete-implementation",
        severity: "error",
        message: `Found ${fixmeMatches.length.toString()} FIXME comment(s)`,
        evidence: fixmeMatches.join("\n"),
      });
    }

    // Check for placeholder implementations (error - not real implementation)
    const placeholderPattern = /placeholder/gi;
    const placeholderMatches = this.extractEvidence(context.outputLogs, placeholderPattern);
    if (placeholderMatches.length > 0) {
      issues.push({
        type: "incomplete-implementation",
        severity: "error",
        message: "Found placeholder implementation",
        evidence: placeholderMatches.join("\n"),
      });
    }

    // Check for stub implementations (error - not real implementation)
    const stubPattern = /\bstub\b/gi;
    const stubMatches = this.extractEvidence(context.outputLogs, stubPattern);
    if (stubMatches.length > 0) {
      issues.push({
        type: "incomplete-implementation",
        severity: "error",
        message: "Found stub implementation",
        evidence: stubMatches.join("\n"),
      });
    }

    // Calculate confidence
    const baseConfidence = 100;
    const penaltyPerIssue = 20; // Increased from 15 to be more aggressive
    const confidence = Math.max(0, baseConfidence - issues.length * penaltyPerIssue);

    return Promise.resolve({
      strategyName: this.name,
      passed: issues.filter((i) => i.severity === "error").length === 0,
      confidence,
      issues,
    });
  }
}
