import type { RegexDiagnostic } from "../model/diagnostics";

export type CorpusDocumentSource = "file" | "pasted-text";
export type CorpusOperation = "match" | "replace";
export type CorpusSubjectMode = "document" | "line";

export interface CorpusDocument {
  readonly id: string;
  readonly name: string;
  readonly text: string;
  readonly bytes: number;
  readonly source: CorpusDocumentSource;
}

export type CorpusDocumentResultStatus =
  "complete" | "partial" | "error" | "cancelled" | "not-run";

export interface CorpusDocumentResult {
  readonly documentId: string;
  readonly name: string;
  readonly inputBytes: number;
  readonly lineCount: number;
  readonly status: CorpusDocumentResultStatus;
  /** Exact only when status is complete; otherwise a retained lower bound. */
  readonly matchCount: number;
  readonly elapsedMs: number;
  readonly output?: string;
  readonly outputBytes?: number;
  readonly changed?: boolean;
  readonly captureSummaries: readonly CorpusCaptureSummary[];
  readonly captureSummariesTruncated: boolean;
  readonly diagnostics: readonly RegexDiagnostic[];
  readonly message?: string;
}

export interface CorpusBatchResult {
  readonly operation: CorpusOperation;
  readonly subjectMode: CorpusSubjectMode;
  readonly status: "complete" | "partial" | "cancelled";
  readonly documents: readonly CorpusDocumentResult[];
  readonly processedDocuments: number;
  readonly totalDocuments: number;
  readonly totalMatches: number;
  readonly totalElapsedMs: number;
  readonly retainedOutputBytes: number;
  readonly message: string;
}

export interface CorpusCaptureSummary {
  readonly groupNumber: number;
  readonly groupName?: string;
  readonly participated: number;
  readonly didNotParticipate: number;
  readonly matchedEmpty: number;
  readonly truncated: number;
  readonly unavailable: number;
  readonly samples: readonly string[];
  readonly samplesClipped: boolean;
}

export interface CorpusProgress {
  readonly completedDocuments: number;
  readonly totalDocuments: number;
  readonly currentDocumentName?: string;
  readonly totalMatches: number;
}
