/**
 * Shared types + constants for the second-brain foundation (SB-S0).
 *
 * The two invariants this module pins (architecture.md §"Invariants"):
 *  - ONE provenance shape across the whole brain: `human | published | ai-draft`.
 *    The model-collapse guard (profile/voice learn from `published` only) hangs on
 *    this being the single source of truth, not reinvented per silo.
 *  - ONE canonical entity-id + one fact record shape (the six fields below), so a
 *    later slice can thread the id through tributaries (SB-S3) without re-deciding
 *    the record schema.
 */

/** The single provenance vocabulary for the whole brain. */
export type Provenance = "human" | "published" | "ai-draft";

/** A fact is `active` until a later, superseding fact demotes it (SB-S2). */
export type FactStatus = "active" | "superseded";

/** The accepted provenance values, as a runtime list (used by normalizeProvenance). */
export const PROVENANCE_VALUES: readonly Provenance[] = ["human", "published", "ai-draft"] as const;

/** The accepted fact-status values, as a runtime list. */
export const FACT_STATUS_VALUES: readonly FactStatus[] = ["active", "superseded"] as const;

/** The profile schema version — bumped only on a breaking grammar change. */
export const SCHEMA_VERSION = 1 as const;

/**
 * One distilled fact in `brain/profile.md`. Every fact carries all six fields so
 * the consolidation loop (SB-S2) has evidence/provenance/temporal context to
 * promote, decay, and reconcile against.
 */
export interface ProfileFact {
  /** Canonical entity id (id.ts), keyed on a stable slug — stable across value edits. */
  id: string;
  /** Single-line value (no embedded newline — enforced by the line-grammar). */
  value: string;
  /** YYYY-MM-DD — first observation. */
  first_seen: string;
  /** YYYY-MM-DD — most recent observation. */
  last_seen: string;
  /** How many independent observations back this fact (threshold-promotion, SB-S2). */
  evidence_count: number;
  /** Where the fact came from — drives provenance-weighted learning. */
  provenance: Provenance;
  /** `active` or `superseded`. */
  status: FactStatus;
}

/** The two-layer profile document: stable `static` facts + evolving `dynamic` facts. */
export interface ProfileDoc {
  schemaVersion: typeof SCHEMA_VERSION;
  static: ProfileFact[];
  dynamic: ProfileFact[];
}
