export type AutoScanCaptureDecision =
  | { kind: "unreadable"; countAsMiss: true }
  | { kind: "stuck"; countAsMiss: true; signature: string }
  | { kind: "duplicate"; countAsDuplicate: true; signature: string }
  | { kind: "new"; countAsParsed: true; signature: string };

export function classifyAutoScanCapture({
  signature,
  lastDetailSignature,
  seen,
}: {
  signature: string;
  lastDetailSignature: string;
  seen: ReadonlySet<string>;
}): AutoScanCaptureDecision {
  if (!signature) return { kind: "unreadable", countAsMiss: true };
  if (signature === lastDetailSignature && seen.has(signature)) return { kind: "stuck", countAsMiss: true, signature };
  if (seen.has(signature)) return { kind: "duplicate", countAsDuplicate: true, signature };
  return { kind: "new", countAsParsed: true, signature };
}

export function shouldAbortAfterConsecutiveMisses(consecutiveMisses: number, threshold = 3) {
  return consecutiveMisses >= threshold;
}
