'use strict';

/**
 * MODEL ERAS — the cutoff, defined ONCE (Session 64).
 *
 * `ledger_entries` mixes grades from before and after the 2026-07-19 fix that
 * revived the probability layer (p_win/ev_pct/model_odds/value were absent on
 * 100% of live grades before it) and widened the grade range. There is no
 * per-row version in that table and the eras cannot be separated retroactively,
 * so EVERY consumer must apply the same boundary rather than inventing its own.
 *
 * A backtest that mixes model eras is worthless — that is the whole reason this
 * constant exists in one place.
 *
 * Going forward, rows carry a real `model_version` (from
 * retentionService.MODEL_VERSION) and `model_snapshots` has clean per-row
 * versioning from day one. The harness should read OUTCOMES from
 * ledger_entries but VERSIONING from model_snapshots.
 */

/** Rows graded at or after this are the post-fix era. */
const ERA_CUTOFF_ISO = '2026-07-19T22:50:00Z';

/** What pre-cutoff rows are labelled. Names the uncertainty; never implies
 *  we know which model produced them. */
const UNKNOWN_ERA = 'pre-retention-unknown';

function isPostFix(gradedAt) {
  if (!gradedAt) return false;
  const t = new Date(gradedAt).getTime();
  if (Number.isNaN(t)) return false;
  return t >= new Date(ERA_CUTOFF_ISO).getTime();
}

module.exports = { ERA_CUTOFF_ISO, UNKNOWN_ERA, isPostFix };
