/**
 * `workflow list` — List all available workflows.
 *
 * Discovers workflows from both bundled and project sources and displays
 * them in a formatted table (or JSON with --json).
 *
 * @example
 *   workflow list
 *   workflow list --json
 */

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

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

interface WorkflowEntry {
  name: string;
  description: string;
  source: 'bundled' | 'project';
}

async function discoverWorkflows(_cwd?: string): Promise<WorkflowEntry[]> {
  throw new Error('not implemented yet: discoverWorkflows');
}

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

export async function listCommand(
  _args: string[],
  options: CliOptions,
): Promise<void> {
  const workflows = await discoverWorkflows(options.cwd);

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

  console.log('Available workflows:');
  console.log('');

  printTable(
    workflows.map((w) => ({
      name: w.name,
      description: w.description,
      source: w.source,
    })),
    [
      { header: 'Name', field: 'name', minWidth: 20 },
      { header: 'Description', field: 'description', minWidth: 30 },
      { header: 'Source', field: 'source', minWidth: 10 },
    ],
  );
}