/**
 * Types for the persistent trend store (research-engine §5, foundation layer).
 *
 * The store is the research engine's accumulating memory: a topic-tagged,
 * provenance-bearing inventory of trend signals captured over time, so the
 * engine reasons over HISTORY instead of starting amnesiac each session. It is
 * the trend-side twin of the lived-specifics bank (scripts/specifics-bank):
 * same deterministic store/dedup/query discipline, different dedupe key
 * (normalized title+URL, since a trend is identified by its headline+source,
 * not by free-text content).
 *
 * GENERIC BY ARCHITECTURE (retning §5 — nisje-agnostisk motor): nothing
 * niche-specific lives in this module. A `TrendRecord` carries free-form
 * `topics` tags and a free-form `source` string; which topics matter and which
 * sources to poll are decided upstream (config/profile + the capture agent),
 * never hard-coded here. The same store serves any niche.
 *
 * Forward-compatible with the profile-evolution / "second brain" architecture:
 * a typed store in the per-user data dir (`${LINKEDIN_STUDIO_DATA}`), so the
 * trend history survives plugin upgrades/reinstalls via the M0 data-path seam.
 * The minimal core here (title, url, source, capturedAt, topics, optional
 * summary) can gain fields (relevance score, first-mover timing, status) in a
 * later slice without breaking the shape.
 */

export interface TrendRecord {
  /** Stable id — a short hash of the normalized title+url; doubles as the dedupe key. */
  id: string;
  /** The trend headline, stored VERBATIM (normalized only to derive the id). */
  title: string;
  /** The source URL, stored VERBATIM (normalized only to derive the id). */
  url: string;
  /** Capture origin: a research-MCP name (e.g. "tavily"), "websearch", or "manual". */
  source: string;
  /** ISO-8601 date the trend was captured. Supplied by the caller (CLI edge). */
  capturedAt: string;
  /** Topic tags for query-by-topic. Unioned across re-captures of the same trend. */
  topics: string[];
  /** Optional short summary of the trend, stored VERBATIM. */
  summary?: string;
}

export interface TrendStore {
  schemaVersion: number;
  trends: TrendRecord[];
}

/** A query hit: the trend plus how many of the queried topics it matched. */
export interface TrendQueryHit {
  trend: TrendRecord;
  /** Number of queried topics present on the trend (≥1 for a hit). */
  topicOverlap: number;
}

export const SCHEMA_VERSION = 1;
