import { withActor } from '../db/index.js'
import { recomputeExpiry } from './jobs/expiry.js'

/**
 * The scheduled-job entry point. Required by #13 decision 4.
 *
 * "Eligibility is a derived value that must be recomputed on a clock, not only
 *  on write. Nothing else on the map has needed a scheduler; this does, and
 *  the layout must have a place for it."
 *
 * Jobs establish actor context WITHOUT a request. That is the whole reason
 * this cannot live behind the HTTP middleware.
 */
export const JOBS = {
  'expiry-recompute': recomputeExpiry,
} as const

export async function runJob(name: keyof typeof JOBS): Promise<void> {
  await withActor({ kind: 'system', job: name }, JOBS[name])
}
