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

export const DATA_NEW_NODES: CatalogNodeEntry[] = [
  {
    type: 'extract_field',
    label: 'Extract Field',
    description: 'Extract a single field from an object or array using dot-notation or JSONPath.',
    category: 'data',
    color: 'text-sky-500',
    iconName: 'Crosshair',
    inputs: [{ name: 'data', type: 'json', required: true, description: 'Source object' }],
    outputs: [{ name: 'value', type: 'any', description: 'Extracted field value' }],
    requiredConfig: ['path'],
    optionalConfig: ['fallback'],
    exampleConfig: { path: 'results[0].analysis.score', fallback: '0' },
    acceptsInputTypes: ['json', 'any'],
    producesOutputType: 'any',
    n8nEquivalent: 'n8n-nodes-base.set',
  },
  {
    type: 'rename_field',
    label: 'Rename Field',
    description: 'Rename keys in a JSON object without changing values.',
    category: 'data',
    color: 'text-sky-500',
    iconName: 'Replace',
    inputs: [{ name: 'data', type: 'json', required: true, description: 'Object to transform' }],
    outputs: [{ name: 'result', type: 'json', description: 'Object with renamed keys' }],
    requiredConfig: ['mappings'],
    optionalConfig: ['keepUnmapped'],
    exampleConfig: { mappings: { old_name: 'newName', created_at: 'createdAt' }, keepUnmapped: true },
    acceptsInputTypes: ['json', 'any'],
    producesOutputType: 'json',
    n8nEquivalent: 'n8n-nodes-base.renameKeys',
  },
  {
    type: 'filter_items',
    label: 'Filter Items',
    description: 'Filter an array of items based on a condition expression.',
    category: 'data',
    color: 'text-sky-500',
    iconName: 'Filter',
    inputs: [{ name: 'items', type: 'array', required: true, description: 'Array to filter' }],
    outputs: [{ name: 'filtered', type: 'array', description: 'Items matching the condition' }],
    requiredConfig: ['condition'],
    optionalConfig: ['limit'],
    exampleConfig: { condition: 'item.score >= 0.8 && item.status === "active"', limit: 50 },
    acceptsInputTypes: ['array', 'json', 'any'],
    producesOutputType: 'array',
    n8nEquivalent: 'n8n-nodes-base.filter',
  },
  {
    type: 'aggregate',
    label: 'Aggregate',
    description: 'Reduce an array to a single value using sum, count, avg, min, max, or concat.',
    category: 'data',
    color: 'text-sky-500',
    iconName: 'Calculator',
    inputs: [{ name: 'items', type: 'array', required: true, description: 'Array to aggregate' }],
    outputs: [{ name: 'result', type: 'json', description: 'Aggregation result with value and count' }],
    requiredConfig: ['operation', 'field'],
    optionalConfig: ['groupBy'],
    exampleConfig: { operation: 'avg', field: 'score', groupBy: 'category' },
    acceptsInputTypes: ['array', 'json'],
    producesOutputType: 'json',
    n8nEquivalent: 'n8n-nodes-base.aggregate',
  },
  {
    type: 'sort',
    label: 'Sort',
    description: 'Sort an array of items by one or more fields.',
    category: 'data',
    color: 'text-sky-500',
    iconName: 'ArrowUpDown',
    inputs: [{ name: 'items', type: 'array', required: true, description: 'Array to sort' }],
    outputs: [{ name: 'sorted', type: 'array', description: 'Sorted array' }],
    requiredConfig: ['field'],
    optionalConfig: ['direction', 'secondaryField'],
    exampleConfig: { field: 'score', direction: 'desc', secondaryField: 'created_at' },
    acceptsInputTypes: ['array', 'json'],
    producesOutputType: 'array',
    n8nEquivalent: 'n8n-nodes-base.sort',
  },
  {
    type: 'deduplicate',
    label: 'Deduplicate',
    description: 'Remove duplicate items from an array based on a key field.',
    category: 'data',
    color: 'text-sky-500',
    iconName: 'CopyMinus',
    inputs: [{ name: 'items', type: 'array', required: true, description: 'Array with potential duplicates' }],
    outputs: [{ name: 'unique', type: 'array', description: 'Deduplicated array' }],
    requiredConfig: ['key'],
    optionalConfig: ['keepFirst'],
    exampleConfig: { key: 'id', keepFirst: true },
    acceptsInputTypes: ['array', 'json'],
    producesOutputType: 'array',
    n8nEquivalent: 'n8n-nodes-base.removeDuplicates',
  },
  {
    type: 'text_splitter',
    label: 'Text Splitter',
    description: 'Split text into chunks by separator, token count, or character limit for RAG pipelines.',
    category: 'data',
    color: 'text-sky-500',
    iconName: 'Scissors',
    inputs: [{ name: 'text', type: 'text', required: true, description: 'Text to split' }],
    outputs: [{ name: 'chunks', type: 'document[]', description: 'Array of text chunks with metadata' }],
    requiredConfig: ['strategy'],
    optionalConfig: ['chunkSize', 'overlap', 'separator'],
    exampleConfig: { strategy: 'token', chunkSize: 512, overlap: 64 },
    acceptsInputTypes: ['text', 'any'],
    producesOutputType: 'document[]',
    n8nEquivalent: '@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter',
  },
  {
    type: 'data_mapper',
    label: 'Data Mapper',
    description: 'Transform objects by mapping source fields to target fields with optional type coercion.',
    category: 'data',
    color: 'text-sky-500',
    iconName: 'ArrowRightLeft',
    inputs: [{ name: 'input', type: 'json', required: true, description: 'Source data object' }],
    outputs: [{ name: 'mapped', type: 'json', description: 'Transformed output object' }],
    requiredConfig: ['mappings'],
    optionalConfig: ['strict', 'includeUnmapped'],
    exampleConfig: {
      mappings: [
        { source: 'n1.text', target: 'summary', transform: 'trim' },
        { source: 'n2.score', target: 'rating', transform: 'toNumber' },
      ],
      strict: false,
    },
    acceptsInputTypes: ['json', 'any'],
    producesOutputType: 'json',
    n8nEquivalent: 'n8n-nodes-base.set',
  },
]
