/**
 * `workflow resume` — Resume a failed workflow run.
 *
 * Skips completed nodes and re-executes from the failure point.
 *
 * @example
 *   workflow resume abc123
 *   workflow resume abc123 --json
 */

import { printJson, type CliOptions } from "../utils.js";

// ---------------------------------------------------------------------------
// Stub: engine integration (not implemented yet)
// ---------------------------------------------------------------------------

interface ResumeResult {
  runId: string;
  resumed: boolean;
  message: string;
}

async function resumeWorkflowRun(_runId: string): Promise<ResumeResult> {
  throw new Error('not implemented yet: resumeWorkflowRun');
}

// ---------------------------------------------------------------------------
// Command handler
// ---------------------------------------------------------------------------

export async function resumeCommand(
  args: string[],
  options: CliOptions,
): Promise<void> {
  if (args.length === 0) {
    throw new Error('Missing required argument: <run-id>\n\nUsage: workflow resume <run-id> [--json]');
  }

  const runId = args[0]!;

  const result = await resumeWorkflowRun(runId);

  if (options.json) {
    printJson(result);
    return;
  }

  if (result.resumed) {
    console.log(`↻ Run ${result.runId} resumed.`);
    console.log(`  ${result.message}`);
  } else {
    console.log(`Failed to resume run ${result.runId}: ${result.message}`);
  }
}