import type { JobHandler } from './types.js';

// ── Job Registry ─────────────────────────────────────────────
// Register named jobs with handlers. The runner evaluates cron
// and dispatches to the registered handler.

const handlers = new Map<string, JobHandler>();

export function registerJob(name: string, handler: JobHandler): void {
  if (handlers.has(name)) {
    throw new Error(`Job '${name}' is already registered`);
  }
  handlers.set(name, handler);
}

export function getJobHandler(name: string): JobHandler | undefined {
  return handlers.get(name);
}

export function getRegisteredJobs(): string[] {
  return Array.from(handlers.keys());
}

export function clearRegistry(): void {
  handlers.clear();
}
