/**
 * `workflow reject` — Reject a paused workflow run.
 *
 * Sets $REJECTION_REASON with the provided reason string.
 *
 * @example
 *   workflow reject abc123
 *   workflow reject abc123 "Not compliant" --json
 */

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

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

interface RejectResult {
  runId: string;
  rejected: boolean;
  reason?: string;
  message: string;
}

async function rejectWorkflowRun(
  _runId: string,
  _reason?: string,
): Promise<RejectResult> {
  throw new Error('not implemented yet: rejectWorkflowRun');
}

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

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

  const runId = args[0]!;
  const reason = args.length > 1 ? args.slice(1).join(' ') : undefined;

  const result = await rejectWorkflowRun(runId, reason);

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

  if (result.rejected) {
    console.log(`✗ Run ${result.runId} rejected.`);
    if (result.reason) {
      console.log(`  Reason: ${result.reason}`);
    }
  } else {
    console.log(`Failed to reject run ${result.runId}: ${result.message}`);
  }
}