/**
 * CLI.2 — `opensquid schedule list|next|history|add|remove|pause|resume|run`.
 *
 * Thin commander wiring. Verb bodies live in `./schedule_actions.ts`;
 * persistence + status + next-fire helpers in `./schedule_state.ts`; table
 * rendering in `./schedule_render.ts`. This file ONLY routes commander
 * options/args into the action functions and resolves default paths from
 * `OPENSQUID_HOME()`.
 *
 * Verb semantics (locked):
 *
 *   list      — pack-declared + user-added merged; `--status` filters per
 *               SCHED.4 wedge-gate sentinel.
 *   next      — minute-by-minute walk over each schedule's cron; daemon-free.
 *   history   — JSONL outcomes from SCHED.4 per-session + force-fire log.
 *   add       — `--cron <expr>` bypasses NL→cron (no LLM call). Otherwise
 *               routes through `nlToCron` (SCHED.3 `fast_classifier`).
 *   remove    — confirms unless `--yes`; user-added only.
 *   pause/    — user-added only (pack-declared: use `triggers disable|
 *     resume    enable`).
 *   run       — force-fire once; appends `cli.run` history entry; dispatches
 *               if a daemon is wired.
 *
 * Imports from: commander, ./schedule_actions, ./schedule_state,
 *   ./triggers_state.
 * Imported by: src/cli.ts.
 */
import { actAdd, actHistory, actList, actNext, actPauseResume, actRemove, actRun, } from './schedule_actions.js';
import { defaultHistoryPath, defaultPausedPath, defaultSessionsDir, defaultUserSchedulesPath, } from './schedule_state.js';
import { defaultPacksDir } from './triggers_state.js';
export { renderListTable, renderNextTable } from './schedule_render.js';
const defaultIsTty = () => process.stdout.isTTY === true;
function buildDeps(deps) {
    const actionDeps = {
        paths: {
            packsDir: deps.packsDir ?? defaultPacksDir(),
            userSchedulesPath: deps.userSchedulesPath ?? defaultUserSchedulesPath(),
            pausedPath: deps.pausedPath ?? defaultPausedPath(),
            historyPath: deps.historyPath ?? defaultHistoryPath(),
            sessionsDir: deps.sessionsDir ?? defaultSessionsDir(),
        },
        out: deps.stdout ?? ((s) => process.stdout.write(s)),
        err: deps.stderr ?? ((s) => process.stderr.write(s)),
        isTty: deps.isTty ?? defaultIsTty,
        now: deps.now ?? (() => new Date()),
    };
    if (deps.dispatch !== undefined)
        actionDeps.dispatch = deps.dispatch;
    return actionDeps;
}
export function registerSchedule(parent, deps = {}) {
    const ad = buildDeps(deps);
    const s = parent.command('schedule').description('Manage scheduled jobs');
    s.command('list')
        .description('List all schedules (pack-declared + user-added)')
        .option('--pack <pack>')
        .option('--status <status>', 'probationary|permanent|retired')
        .action((opts) => actList(ad, opts));
    s.command('next')
        .description('Upcoming firings (next 10 by default)')
        .option('--limit <n>', '10', '10')
        .action((opts) => actNext(ad, opts));
    s.command('history')
        .description('Recent fires across all schedules (force-fires + scheduled fires)')
        .option('--limit <n>', '50', '50')
        .option('--id <scheduleId>', 'restrict to one schedule')
        .action((opts) => actHistory(ad, opts));
    s.command('add <description>')
        .description('Add a schedule. <description> is NL or pass --cron for an exact expression.')
        .option('--cron <expr>', 'exact 5-field POSIX cron expression (skips NL→cron translation)')
        .requiredOption('--pack <pack>')
        .requiredOption('--skill <skill>')
        .option('--cost-tier <tier>', 'cheap|balanced|premium')
        .option('--timezone <tz>', 'IANA timezone (defaults to UTC)')
        .action((description, opts) => actAdd(ad, description, opts));
    s.command('remove <id>')
        .description('Remove a user-added schedule (confirms unless --yes)')
        .option('--yes', 'skip confirmation', false)
        .action((id, opts) => actRemove(ad, id, opts));
    s.command('pause <id>')
        .description('Pause a user-added schedule (pack-declared: use triggers disable)')
        .action((id) => actPauseResume(ad, 'pause', id));
    s.command('resume <id>')
        .description('Resume a user-added schedule (pack-declared: use triggers enable)')
        .action((id) => actPauseResume(ad, 'resume', id));
    s.command('run <id>')
        .description('Force-fire a schedule once (writes history; dispatches if daemon wired)')
        .option('--yes', 'skip confirmation', false)
        .action((id, opts) => actRun(ad, id, opts));
    return s;
}
//# sourceMappingURL=schedule.js.map