import { getTechStepReference, type TechStepReference } from "./api-client.js";

/**
 * Loads the `TechStep` taxonomy the worker judges/labels clauses against —
 * always from `GET /reference/tech-steps` (`api-client.ts`), never a
 * hardcoded local copy. `experiments/llm-tech-step-poc`'s own taxonomy
 * (`shared/kitchen-action.ts`'s 7-category `KitchenActionType`) is
 * deliberately *not* reused here: this worker judges against the real
 * production `TechStep` catalog (~26 techniques), a different, finer-
 * grained taxonomy that PoC never tested — reading it fresh from the API
 * is what keeps this worker from ever silently drifting out of sync with
 * whatever `apps/api`'s `TechStep` table actually contains.
 *
 * Fetched once per process (the scheduler's "load model, run jobs, dispose"
 * cycle — see `scheduler.ts` — already re-fetches this on every scheduled
 * wake-up, so a catalog change is picked up within one cycle without
 * needing its own cache invalidation).
 */
export async function loadTechStepTaxonomy(): Promise<TechStepReference[]> {
  const techSteps = await getTechStepReference();
  if (techSteps.length === 0) {
    throw new Error(
      "GET /reference/tech-steps returned an empty catalog — refusing to judge clauses against no known techniques at all.",
    );
  }
  return techSteps;
}
