import { Node as ReactFlowNode } from '@xyflow/react';

/**
 * Data structure for workflow nodes in ReactFlow
 * Extended with index signature for ReactFlow compatibility
 */
export interface WorkflowNodeData extends Record<string, unknown> {
  name: string;
  icon: string;
  status: 'valid' | 'error' | 'warning' | 'unconfigured' | 'placeholder';
  errorCount?: number;
  /** Action configuration - dynamic key-value pairs based on action type schema */
  config?: Record<string, unknown>;
  actionType?: string;
  /** User-defined label for namespaced context (e.g., "CreatePost", "SendEmail") */
  label?: string;
  /** Step number in the workflow sequence (1-based) */
  stepNumber?: number;
  /** App/service name for branding (e.g., "WordPress", "Mailchimp") */
  appName?: string;
  /** App/service identifier for icon lookup (e.g., "wordpress", "mailchimp") */
  appService?: string;
  /** For placeholder nodes: indicates if this is a trigger or action placeholder */
  placeholderType?: 'trigger' | 'action';
  /** Callback when edit/configure is clicked */
  onEdit?: (nodeId: string) => void;
  /** Callback when duplicate is clicked */
  onDuplicate?: (nodeId: string) => void;
  /** Callback when delete is clicked */
  onDelete?: (nodeId: string) => void;
  /** Callback when placeholder node is clicked to select an app */
  onSelectApp?: (nodeId: string) => void;
  /** Callback when "View Data Fields" is clicked (trigger nodes only) */
  onViewDataFields?: (nodeId: string) => void;
  /** Brief summary of key configuration for display on node card */
  configSummary?: string;
  /** Number of output fields available (for triggers) */
  fieldCount?: number;
}

/**
 * Type for workflow node types
 * - trigger: Starts a workflow when an event occurs
 * - action: Performs an operation in the workflow
 * - operator: Conditional logic or data transformation node
 * - addStep: Pseudo-node for adding new steps (not persisted)
 */
export type WorkflowNodeType = 'trigger' | 'action' | 'operator' | 'addStep';

/**
 * Extended ReactFlow Node type with custom workflow data
 */
export type WorkflowReactFlowNode = ReactFlowNode<WorkflowNodeData, WorkflowNodeType>;
