import type { CatalogNodeEntry } from '../workflow-node-catalog'

export const UTILITY_NODES: CatalogNodeEntry[] = [
  {
    type: 'logger',
    label: 'Logger',
    description: 'Log a message or data to the workflow execution trace for debugging.',
    category: 'utility',
    color: 'text-gray-500',
    iconName: 'ScrollText',
    inputs: [{ name: 'data', type: 'any', description: 'Data to log' }],
    outputs: [{ name: 'passthrough', type: 'any', description: 'Input data passed through unchanged' }],
    requiredConfig: [],
    optionalConfig: ['level', 'label', 'includeTimestamp'],
    exampleConfig: {
      level: 'info',
      label: 'After RAG retrieval',
      includeTimestamp: true,
    },
    acceptsInputTypes: ['any'],
    producesOutputType: 'any',
    n8nEquivalent: 'n8n-nodes-base.noOp',
  },
  {
    type: 'debug_inspector',
    label: 'Debug Inspector',
    description: 'Inspect and display the current workflow state, node outputs, and data shapes.',
    category: 'utility',
    color: 'text-gray-500',
    iconName: 'Bug',
    inputs: [{ name: 'data', type: 'any', description: 'Data to inspect' }],
    outputs: [
      { name: 'passthrough', type: 'any', description: 'Input data passed through unchanged' },
      { name: 'inspection', type: 'json', description: 'Inspection report (types, shapes, sizes)' },
    ],
    requiredConfig: [],
    optionalConfig: ['maxDepth', 'showTypes', 'showSizes'],
    exampleConfig: {
      maxDepth: 3,
      showTypes: true,
      showSizes: true,
    },
    acceptsInputTypes: ['any'],
    producesOutputType: 'any',
  },
  {
    type: 'secret_resolver',
    label: 'Secret Resolver',
    description: 'Resolve a secret from the encrypted vault and inject it into the workflow context.',
    category: 'utility',
    color: 'text-gray-500',
    iconName: 'KeyRound',
    inputs: [{ name: 'trigger', type: 'any', description: 'Any input triggers resolution' }],
    outputs: [{ name: 'resolved', type: 'json', description: 'Resolved secret reference (never exposes raw value)' }],
    requiredConfig: ['secretName'],
    optionalConfig: ['provider', 'scope'],
    exampleConfig: {
      secretName: 'OPENAI_API_KEY',
      provider: 'vault',
      scope: 'workflow',
    },
    acceptsInputTypes: ['any', 'void'],
    producesOutputType: 'json',
  },
  {
    type: 'rate_limit',
    label: 'Rate Limit',
    description: 'Throttle execution to a maximum number of invocations per time window.',
    category: 'utility',
    color: 'text-gray-500',
    iconName: 'Gauge',
    inputs: [{ name: 'input', type: 'any', description: 'Data to pass through after rate check' }],
    outputs: [
      { name: 'allowed', type: 'any', description: 'Input passed through if within limit' },
      { name: 'throttled', type: 'json', description: 'Throttle info if rate exceeded' },
    ],
    requiredConfig: ['maxRequests', 'windowMs'],
    optionalConfig: ['key', 'strategy'],
    exampleConfig: {
      maxRequests: 60,
      windowMs: 60000,
      key: 'email_send_{{ctx.lenserId}}',
      strategy: 'sliding_window',
    },
    acceptsInputTypes: ['any'],
    producesOutputType: 'any',
  },
  {
    type: 'cache_read',
    label: 'Cache Read',
    description: 'Read a cached value by key, returning miss status if not found.',
    category: 'utility',
    color: 'text-gray-500',
    iconName: 'DatabaseZap',
    inputs: [{ name: 'trigger', type: 'any', description: 'Any input triggers the cache lookup' }],
    outputs: [
      { name: 'value', type: 'any', description: 'Cached value if found' },
      { name: 'hit', type: 'boolean', description: 'Whether the cache key was found' },
    ],
    requiredConfig: ['key'],
    optionalConfig: ['namespace'],
    exampleConfig: {
      key: 'digest_{{ctx.date}}',
      namespace: 'workflow_cache',
    },
    acceptsInputTypes: ['any', 'void'],
    producesOutputType: 'any',
  },
  {
    type: 'cache_write',
    label: 'Cache Write',
    description: 'Write a value to the cache with a configurable TTL.',
    category: 'utility',
    color: 'text-gray-500',
    iconName: 'DatabaseZap',
    inputs: [{ name: 'value', type: 'any', required: true, description: 'Value to cache' }],
    outputs: [{ name: 'confirmation', type: 'json', description: 'Cache write confirmation with key and expiry' }],
    requiredConfig: ['key'],
    optionalConfig: ['ttlMs', 'namespace'],
    exampleConfig: {
      key: 'digest_{{ctx.date}}',
      ttlMs: 86400000,
      namespace: 'workflow_cache',
    },
    acceptsInputTypes: ['text', 'json', 'any'],
    producesOutputType: 'json',
  },
  {
    type: 'retry',
    label: 'Retry',
    description: 'Retry a failed upstream node with configurable backoff strategy.',
    category: 'utility',
    color: 'text-gray-500',
    iconName: 'RotateCcw',
    inputs: [{ name: 'error', type: 'error', required: true, description: 'Error from a failed upstream node' }],
    outputs: [
      { name: 'result', type: 'any', description: 'Successful retry output' },
      { name: 'exhausted', type: 'error', description: 'Final error after all retries exhausted' },
    ],
    requiredConfig: ['maxRetries'],
    optionalConfig: ['backoffStrategy', 'initialDelayMs', 'maxDelayMs', 'retryableErrors'],
    exampleConfig: {
      maxRetries: 3,
      backoffStrategy: 'exponential',
      initialDelayMs: 1000,
      maxDelayMs: 30000,
      retryableErrors: ['TIMEOUT', 'RATE_LIMITED', 'SERVICE_UNAVAILABLE'],
    },
    acceptsInputTypes: ['error', 'any'],
    producesOutputType: 'any',
  },
  {
    type: 'noop',
    label: 'No-Op',
    description: 'Pass data through without modification. Useful for graph layout and documentation.',
    category: 'utility',
    color: 'text-gray-500',
    iconName: 'Minus',
    inputs: [{ name: 'input', type: 'any', description: 'Any data' }],
    outputs: [{ name: 'output', type: 'any', description: 'Same data, unchanged' }],
    requiredConfig: [],
    optionalConfig: ['note'],
    exampleConfig: { note: 'Placeholder for future processing step' },
    acceptsInputTypes: ['any'],
    producesOutputType: 'any',
    n8nEquivalent: 'n8n-nodes-base.noOp',
  },
]
