/**
 * resolve-per-area-baselines.ts
 *
 * Pure per-area baseline resolution for pipeline auto-comparison
 * (W-resolve-per-area-baselines).
 *
 * The whole-report selector ({@link selectComparableBaseline}) picks a single
 * prior report that must cover EVERY area the current run scored. Production
 * runs have heterogeneous area coverage — full 9-area sweeps, single-area
 * ad-hoc runs, release-scoped runs — so a single fully-covering baseline often
 * does not exist, and the whole-report selector then declines to compare at all
 * (the report publishes with no deltas).
 *
 * This module generalizes selection to the architectural model: resolve EACH
 * area's baseline independently. "For `content-lake`, find the most recent
 * comparable prior report that actually scored `content-lake`." Deltas then
 * stay meaningful no matter how runs are sliced.
 *
 * The comparability gate is identical to whole-report selection — same
 * `classification` (trend series, D0037) and `variant` (scoring methodology) —
 * reused via {@link filterComparableCandidates} so the two paths can never
 * drift. The only difference is the area predicate: whole-report needs one
 * candidate covering all areas; per-area needs, for each area, the most recent
 * candidate covering THAT area.
 *
 * In the homogeneous case (every current area was scored by the most recent
 * comparable run) every area resolves to that one run, so per-area resolution
 * collapses to exactly the whole-report result — the per-area deltas and
 * overall delta are value-identical, and only the `baselineSources` attribution
 * is added.
 *
 * Pure: no I/O, no clock, no Sanity client. The caller (`ReportStore`) fetches
 * a slim candidate projection via GROQ and feeds it here; the area predicate
 * can't ride GROQ's indexed `Aggregate` path (array-membership forces a full
 * `Fetch`), so it lives in TypeScript where it is also directly unit-testable.
 */
import { type BaselineCandidate, type BaselineQuery, type ComparabilityGateReason } from "./select-baseline.js";
import type { ISOTimestamp, ReportId } from "./types.js";
/** Which prior report supplies one area's baseline score. */
export interface AreaBaselineSource {
    /** The feature area this baseline covers. */
    area: string;
    /** When the supplying report completed (most-recent-first tie-break + display). */
    completedAt: ISOTimestamp;
    /** The supplying report's id. */
    reportId: ReportId;
}
/** Why per-area resolution resolved the way it did (diagnostic + log signal). */
export type PerAreaResolutionReason = "no-area-coverage" | ComparabilityGateReason | "resolved";
/**
 * Outcome of per-area baseline resolution.
 *
 * `resolved` carries one entry per area that found a comparable prior; the
 * remaining current-run areas land in `unresolved` and are reported as
 * not-comparable (never `currentScore - 0`, consistent with
 * W-mark-uncomparable-areas).
 */
export interface PerAreaResolution {
    /**
     * The single "primary" baseline — the report that supplied the most areas,
     * tie-broken most-recent. Recorded on `provenance.lineage.comparedAgainst`
     * for back-compat with single-baseline consumers. `null` when nothing
     * resolved.
     */
    primaryReportId: null | ReportId;
    /** Why resolution ended as it did; `resolved` when ≥1 area found a baseline. */
    reason: PerAreaResolutionReason;
    /** Per-area baseline attribution, one entry per area that resolved. */
    resolved: AreaBaselineSource[];
    /** Current-run areas with no comparable prior that scored them. */
    unresolved: string[];
}
/**
 * Choose the primary report from a set of per-area sources: the report covering
 * the most areas, tie-broken by most-recent `completedAt`. In the common
 * homogeneous case every area resolves to the same report, so this is simply
 * that report.
 *
 * Exported so the impure caller can recompute the primary from the sources it
 * actually used (after dropping any area whose winning report's `scores[]`
 * disagreed with its `provenance.areas`), keeping `lineage.comparedAgainst` from
 * ever naming a report that contributed no baseline score.
 */
export declare function pickPrimaryReportId(resolved: readonly AreaBaselineSource[]): ReportId;
/**
 * Resolve each current-run area's baseline independently from a candidate list.
 *
 * The candidate list need not be pre-sorted — the shared comparability gate
 * sorts most-recent-first. For each current area, the first (most recent)
 * comparable candidate whose area set includes that area wins. Areas no
 * comparable candidate scored are returned in `unresolved`.
 *
 * @see filterComparableCandidates — the shared classification + variant gate
 * @see selectComparableBaseline — the whole-report counterpart
 */
export declare function resolvePerAreaBaselines(current: BaselineQuery, candidates: readonly BaselineCandidate[]): PerAreaResolution;
