/**
 * Canonical list of all workflow node types.
 *
 * This is the SINGLE SOURCE OF TRUTH for node type strings.
 * When you add a new type here, TypeScript will force you to handle it
 * in the executeNode() switch — otherwise the build fails.
 */
export const ALL_NODE_TYPES = [
  // TRIGGER
  'cron_trigger',
  'webhook_trigger',
  'event_trigger',
  'manual_trigger',
  // ACTION (calls an activity)
  'http_request',
  'db_query',
  'db_execute',
  'send_notification',
  'code',
  // DATA PROCESSING (inline logic)
  'set_variable',
  // CONDITION (inline logic)
  'if_else',
  'switch',
  // FLOW CONTROL
  'for_each',
  'delay',
  'parallel',
  'error_handler',
  // APPROVAL (Temporal signal)
  'approval',
  // SUB WORKFLOW
  'sub_workflow',
] as const;

/** Union of all supported node type strings. */
export type NodeType = (typeof ALL_NODE_TYPES)[number];

/** Node types that require a Temporal activity call. */
export const ACTIVITY_NODE_TYPES = [
  'http_request',
  'db_query',
  'db_execute',
  'send_notification',
  'code',
] as const satisfies readonly NodeType[];

export type ActivityNodeType = (typeof ACTIVITY_NODE_TYPES)[number];

/**
 * Compile-time exhaustiveness check.
 * Place in the `default` of a switch over NodeType — if a case is missing,
 * TypeScript emits: "Argument of type 'X' is not assignable to parameter of type 'never'."
 */
export function assertNever(x: never): never {
  throw new Error(`Unhandled node type: ${x}`);
}
