/**
 * Types for the lived-specifics bank (Fix #2 — kilde-så-draft).
 *
 * The bank is the operator's inventory of REAL, un-generatable raw material:
 * the specific measured number, the named (anonymized-but-real) case, the thing
 * that actually broke, the unfashionable opinion privately held, the moment they
 * changed their mind. The taxonomy mirrors the dream-spec's "Lived-Specifics
 * Extraction" engine (docs/expert-review/dream-spec.local.md): sourcing, not
 * styling, is where authenticity is won — so drafts must draw from real
 * inventory instead of inventing plausible filler.
 *
 * INVARIANT (retning §3 — «ditt råmateriale, verktøyets håndverk»): every
 * `content` is the OPERATOR's own words, captured through elicitation. The bank
 * never holds AI-generated lived experience. The store half lives here
 * (deterministic, testable); the elicitation interview lives in the command.
 *
 * Forward-compatible with the profile-evolution / "second brain" architecture:
 * a typed, tag- and provenance-bearing knowledge store in the per-user data dir
 * (`${LINKEDIN_STUDIO_DATA}`), so it survives plugin upgrades/reinstalls via the
 * existing M0 data-path seam. New `SpecificType`s or cross-references can be
 * added without breaking the shape.
 */

/** The un-generatable taxonomy (dream-spec line 56). */
export type SpecificType =
  | "number" // a real, measured number (must be fact-checked — regel 6/7)
  | "named-case" // a named (anonymized-but-real) client / project / person
  | "what-broke" // the thing that actually went wrong / broke
  | "contrarian" // an unfashionable opinion the operator privately holds
  | "mind-change" // a moment the operator changed their mind
  | "other"; // real material that does not fit the above

/** Whether a checkable claim (esp. a number) has been verified to a source. */
export type Verification = "verified" | "unverified" | "n/a";

/** Active material is offered by query; archived material is kept but not offered. */
export type SpecificStatus = "active" | "archived";

export interface Provenance {
  /** ISO-8601 date the material was captured. Supplied by the caller (CLI edge). */
  capturedAt: string;
  /** Where it was captured: an edition id (e.g. "seres/05"), a command, or "manual". */
  source: string;
}

export interface Specific {
  /** Stable id — a short hash of the normalized content; doubles as the dedupe key. */
  id: string;
  type: SpecificType;
  /** The operator's raw material, in their words. NEVER AI-generated. */
  content: string;
  /** Topic tags for query-by-topic. Unioned across re-captures of the same content. */
  topicTags: string[];
  provenance: Provenance;
  /** Numbers must be fact-checked before a draft asserts them as fact (regel 6/7). */
  verification: Verification;
  status: SpecificStatus;
  /**
   * Editions this material was actually published in ("seres/05"), appended at
   * lock. Additive-optional: absent means never used, so existing banks load
   * unchanged and the schema stays v1. The dedupe in `addSpecific` deliberately
   * ENCOURAGES re-surfacing the same material; this field is what makes the
   * re-use visible to the operator at Step 1.5 instead of silent (N11 / C-5).
   */
  usedIn?: string[];
}

export interface Bank {
  schemaVersion: number;
  specifics: Specific[];
}

/** A query hit: the specific plus how many of the queried tags it matched. */
export interface QueryHit {
  specific: Specific;
  /** Number of queried tags present on the specific (≥1 for a hit). */
  tagOverlap: number;
}

export const SCHEMA_VERSION = 1;
