/**
 * Calibration anchors — deliberately EMPTY, and that is a real gap, not an
 * oversight. Read this before you trust a single score this app produces.
 *
 * notes/07-ai-grading.md Rule 3: "Age calibration is the single biggest risk. An
 * LLM's untuned standard for 'a clear explanation' is adult-professional.
 * Applied to a Grade 5 response it will systematically under-score, and the
 * result looks like a real deficit. This is the most likely way this project
 * produces confidently wrong data."
 *
 * The mitigation Rule 3 names is real exemplars — two or three ACTUAL responses
 * per score point, at the actual grade. Not descriptions of what a good response
 * looks like. Real samples.
 *
 * Those cannot be invented here. A plausible-looking fabricated exemplar is
 * worse than no exemplar at all: it would miscalibrate the scale while looking
 * exactly like calibration, which is the precise failure this rule is guarding
 * against. So the array below stays empty until real anchors are added, and
 * every score produced without them is stamped `-uncalibrated` in its permanent
 * audit trail (see rubricVersionFor in ./rubrics.ts).
 *
 * WHERE TO GET THEM — Rule 3 names the source:
 * CDE publishes released CAASPP constructed-response items together with scoring
 * rubrics and annotated student work samples. Those annotations were written by
 * people whose job was calibrating to grade level, which is exactly what is
 * needed here. Use released items as anchors; write original items for the
 * actual tests (never secure items).
 *   https://www.cde.ca.gov/ta/tg/ca/practicetest.asp
 *   https://www.smarterbalanced.org/assessments/practice-and-training-tests/
 *
 * Rule 8 is the other half and is not optional: before the first real
 * administration, Eric hand-grades ~20% of a pilot set and compares against the
 * AI scores. If they diverge systematically the rubric is wrong — fix it and
 * re-run. An unvalidated grader that reads plausibly is worse than no grader,
 * because its output looks like data.
 */

export interface Anchor {
  constructCode: string
  dimensionCode: string
  /** The score this response actually earned. */
  value: number
  /** Grade level of the student who wrote it — the calibration point. */
  grade: number
  /** One line on what the item asked, for context. */
  itemSummary: string
  /** The response, verbatim, including its errors. */
  response: string
  /** Why it earned that score, from the official annotation. */
  justification: string
}

export const ANCHORS: Anchor[] = [
  // Intentionally empty. See the file comment above before adding: anchors must
  // be REAL student responses at the real grade, from CDE's annotated samples.
]

export function anchorsFor(constructCode: string): Anchor[] {
  return ANCHORS.filter((a) => a.constructCode === constructCode).sort(
    (a, b) =>
      a.dimensionCode.localeCompare(b.dimensionCode) || a.value - b.value,
  )
}

export function hasAnchors(constructCode: string): boolean {
  return ANCHORS.some((a) => a.constructCode === constructCode)
}
