import type { VerificationContext, StrategyResult } from "../interfaces";

export abstract class BaseVerificationStrategy {
  abstract name: string;

  abstract verify(context: VerificationContext): Promise<StrategyResult>;

  protected extractEvidence(text: string, pattern: RegExp): string[] {
    const matches: string[] = [];
    const lines = text.split("\n");

    for (const line of lines) {
      if (pattern.test(line)) {
        matches.push(line.trim());
      }
    }

    return matches;
  }

  protected extractAllMatches(text: string, pattern: RegExp): string[] {
    const matches: string[] = [];
    let match: RegExpExecArray | null;

    // Reset lastIndex for global regex
    pattern.lastIndex = 0;

    while ((match = pattern.exec(text)) !== null) {
      matches.push(match[0]);
    }

    return matches;
  }
}
