/**
 * conflictCandidateAnalysis — candidate analysis for conflict detection.
 *
 * Determines WHO wins/loses and WHY: builds op records, classifies
 * supersession/redundancy/eventual-override candidates, and manages
 * causal relation inference.
 *
 * @module domain/services/strand/conflictCandidateAnalysis
 */
import ConflictDiagnostic, { type ConflictDiagnosticData } from '../../types/conflict/ConflictDiagnostic.ts';
import { type TickReceipt, type OpOutcome } from '../../types/TickReceipt.ts';
import type Patch from '../../types/Patch.ts';
import ConflictCandidate from './ConflictCandidate.ts';
import OpRecord from './OpRecord.ts';
import type ConflictPipelineContext from './ConflictPipelineContext.ts';
import { type CanonicalOpBlob } from './conflictTargetIdentity.ts';
/**
 * Structural type for a loaded patch frame as produced by ConflictFrameLoader.
 * Typed structurally rather than via `import type { PatchFrame }` because PatchFrame
 * is a JS class and its field types would otherwise be inferred as `any`.
 */
export interface PatchFrame {
    patch: Patch;
    sha: string;
    patchOrder: number;
    context: Map<string, number>;
    receipt: TickReceipt;
}
/**
 * Mutable accumulator for conflict candidates during frame analysis.
 * Declared here as a structural interface so both files can type it
 * without a circular import. The class itself lives in ConflictCandidateCollector.ts.
 */
export interface CollectorState {
    propertyWinnerByTarget: Map<string, OpRecord>;
    propertyAppliedHistory: Map<string, OpRecord[]>;
    equivalentWinnerByTargetEffect: Map<string, OpRecord>;
    candidates: ConflictCandidate[];
}
/**
 * Appends a diagnostic to the accumulator.
 */
export declare function pushDiagnostic(diagnostics: ConflictDiagnostic[], { code, message, severity, data, }: {
    code: string;
    message: string;
    severity?: 'warning' | 'error';
    data?: ConflictDiagnosticData;
}): void;
/**
 * Pushes a diagnostic for a record that could not be fully constructed.
 */
export declare function pushRecordDiagnostic(diagnostics: ConflictDiagnostic[], { code, messagePrefix, frame, opIndex, }: {
    code: string;
    messagePrefix: string;
    frame: PatchFrame;
    opIndex: number;
}): void;
/**
 * Determines the causal relationship between a winning and losing op record.
 */
export declare function inferCausalRelation(winner: OpRecord, loser: OpRecord): 'concurrent' | 'ordered' | 'replay_equivalent' | 'reducer_collapsed' | undefined;
/**
 * Checks whether either record causally observes the other.
 */
export declare function isCausallyOrdered(winner: OpRecord, loser: OpRecord): boolean;
/**
 * Infers a classification note describing the causal relation between winner and loser.
 */
export declare function inferRelationNote(winner: OpRecord, loser: OpRecord): string;
type BuildOpRecordParams = {
    frame: PatchFrame;
    opIndex: number;
    receiptOpIndex: number;
    canonOp: CanonicalOpBlob;
    receiptOutcome: OpOutcome;
    receiptOpType: string;
    diagnostics: ConflictDiagnostic[];
};
type AnalyzeOneOpParams = {
    frame: PatchFrame;
    opIndex: number;
    receiptOpIndex: number;
    receipt: TickReceipt;
    diagnostics: ConflictDiagnostic[];
};
type AnalyzeOneOpResult = {
    record: OpRecord | null;
    nextReceiptOpIndex: number;
};
/**
 * Builds a full OpRecord from a canonical op, its receipt outcome, and frame context.
 */
export declare function buildOpRecord(pipeline: ConflictPipelineContext, params: BuildOpRecordParams): Promise<OpRecord | null>;
/**
 * Analyzes a single operation within a frame.
 */
export declare function analyzeOneOp(pipeline: ConflictPipelineContext, { frame, opIndex, receiptOpIndex, receipt, diagnostics }: AnalyzeOneOpParams): Promise<AnalyzeOneOpResult | null>;
/**
 * Adds a supersession candidate if the record was superseded.
 */
export declare function maybeAddSupersessionCandidate(collector: CollectorState, record: OpRecord, currentPropertyWinner: OpRecord | null): void;
/**
 * Adds a redundancy candidate if the record was redundant.
 */
export declare function maybeAddRedundancyCandidate(collector: CollectorState, record: OpRecord, priorEquivalent: OpRecord | null): void;
/**
 * Tracks an applied record in the collector for property winner and equivalent effect lookups.
 */
export declare function trackAppliedRecord(collector: CollectorState, record: OpRecord): void;
/**
 * Determines whether a record qualifies as an eventual-override loser.
 */
export declare function isEventualOverrideLoser(loser: OpRecord, finalWinner: OpRecord, scannedPatchShas: Set<string>): boolean;
/**
 * Emits eventual override candidates for a single target's applied history.
 */
export declare function emitEventualOverridesForTarget(collector: CollectorState, { history, finalWinner, scannedPatchShas }: {
    history: OpRecord[];
    finalWinner: OpRecord;
    scannedPatchShas: Set<string>;
}): void;
/**
 * Scans applied property history for eventual-override candidates.
 */
export declare function addEventualOverrideCandidates(collector: CollectorState, scannedPatchShas: Set<string>): void;
/**
 * Processes an analyzed record: checks for immediate candidates and tracks applied records.
 */
export declare function processAnalyzedRecord(collector: CollectorState, { record, sha, scannedPatchShas, }: {
    record: OpRecord;
    sha: string;
    scannedPatchShas: Set<string>;
}): void;
type AnalyzeFrameOpsParams = {
    frame: PatchFrame;
    scannedPatchShas: Set<string>;
    diagnostics: ConflictDiagnostic[];
    collector: CollectorState;
};
/**
 * Analyzes all operations in a single patch frame.
 */
export declare function analyzeFrameOps(pipeline: ConflictPipelineContext, { frame, scannedPatchShas, diagnostics, collector }: AnalyzeFrameOpsParams): Promise<void>;
export {};
