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

export const STORAGE_NEW_NODES: CatalogNodeEntry[] = [
  {
    type: 'sql_query',
    label: 'SQL Query',
    description: 'Execute a parameterized read-only SQL query against the Supabase database.',
    category: 'storage',
    color: 'text-amber-500',
    iconName: 'Database',
    inputs: [{ name: 'params', type: 'json', description: 'Query parameter values' }],
    outputs: [{ name: 'rows', type: 'array', description: 'Result rows' }],
    requiredConfig: ['query'],
    optionalConfig: ['params', 'maxRows', 'timeoutMs'],
    exampleConfig: {
      query: 'SELECT id, title, score FROM battles.battles WHERE status = $1 ORDER BY created_at DESC LIMIT $2',
      params: ['completed', 10],
      maxRows: 100,
      timeoutMs: 5000,
    },
    acceptsInputTypes: ['json', 'any', 'void'],
    producesOutputType: 'array',
    n8nEquivalent: 'n8n-nodes-base.postgres',
  },
  {
    type: 'object_storage_upload',
    label: 'Object Storage Upload',
    description: 'Upload a file or binary data to Supabase Storage.',
    category: 'storage',
    color: 'text-amber-500',
    iconName: 'Upload',
    inputs: [{ name: 'data', type: 'any', required: true, description: 'File content, binary, or URL to upload' }],
    outputs: [
      { name: 'url', type: 'text', description: 'Public or signed URL of uploaded object' },
      { name: 'metadata', type: 'json', description: 'Object metadata (size, mime, key)' },
    ],
    requiredConfig: ['bucket', 'path'],
    optionalConfig: ['contentType', 'visibility', 'upsert'],
    exampleConfig: {
      bucket: 'workflow-artifacts',
      path: 'reports/{{ctx.runId}}/output.pdf',
      contentType: 'application/pdf',
      visibility: 'private',
      upsert: true,
    },
    acceptsInputTypes: ['binary', 'text', 'file', 'image', 'audio', 'video', 'any'],
    producesOutputType: 'json',
    n8nEquivalent: 'n8n-nodes-base.s3',
  },
  {
    type: 'object_storage_download',
    label: 'Object Storage Download',
    description: 'Download a file from Supabase Storage by path or signed URL.',
    category: 'storage',
    color: 'text-amber-500',
    iconName: 'Download',
    inputs: [{ name: 'path', type: 'text', description: 'Storage path or upstream URL' }],
    outputs: [
      { name: 'content', type: 'file', description: 'Downloaded file content' },
      { name: 'metadata', type: 'json', description: 'File metadata (size, mime, lastModified)' },
    ],
    requiredConfig: ['bucket', 'path'],
    optionalConfig: ['signedUrlExpiry'],
    exampleConfig: {
      bucket: 'user-attachments',
      path: 'uploads/{{n1.userId}}/document.pdf',
      signedUrlExpiry: 3600,
    },
    acceptsInputTypes: ['text', 'json', 'any', 'void'],
    producesOutputType: 'file',
    n8nEquivalent: 'n8n-nodes-base.s3',
  },
  {
    type: 'http_request',
    label: 'HTTP Request',
    description: 'Make an HTTP request to any external API with full method/header/body control.',
    category: 'storage',
    color: 'text-amber-500',
    iconName: 'Globe',
    inputs: [{ name: 'body', type: 'any', description: 'Request body from upstream' }],
    outputs: [
      { name: 'data', type: 'json', description: 'Response body parsed as JSON' },
      { name: 'status', type: 'number', description: 'HTTP status code' },
      { name: 'headers', type: 'json', description: 'Response headers' },
    ],
    requiredConfig: ['url', 'method'],
    optionalConfig: ['headers', 'body', 'auth', 'timeoutMs', 'retries', 'followRedirects'],
    exampleConfig: {
      url: 'https://api.openai.com/v1/models',
      method: 'GET',
      headers: { Authorization: 'Bearer {{secrets.OPENAI_KEY}}' },
      timeoutMs: 10000,
      retries: 2,
      followRedirects: true,
    },
    acceptsInputTypes: ['text', 'json', 'any', 'void'],
    producesOutputType: 'json',
    n8nEquivalent: 'n8n-nodes-base.httpRequest',
  },
  {
    type: 'graphql_request',
    label: 'GraphQL Request',
    description: 'Execute a GraphQL query or mutation against an external endpoint.',
    category: 'storage',
    color: 'text-amber-500',
    iconName: 'Braces',
    inputs: [{ name: 'variables', type: 'json', description: 'GraphQL query variables' }],
    outputs: [
      { name: 'data', type: 'json', description: 'GraphQL response data' },
      { name: 'errors', type: 'array', description: 'GraphQL errors if any' },
    ],
    requiredConfig: ['endpoint', 'query'],
    optionalConfig: ['variables', 'headers', 'operationName'],
    exampleConfig: {
      endpoint: 'https://api.github.com/graphql',
      query: 'query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { stargazerCount } }',
      variables: { owner: 'conectlens', name: 'lenserfight' },
      headers: { Authorization: 'Bearer {{secrets.GITHUB_TOKEN}}' },
    },
    acceptsInputTypes: ['json', 'any', 'void'],
    producesOutputType: 'json',
    n8nEquivalent: 'n8n-nodes-base.graphql',
  },
]
