/**
 * Shared condition operators for If/Else and Switch nodes.
 * Type-dependent: number gets <, >, etc.; string gets contains, equals, etc.
 */

import type { FieldType } from './RefSourceSelect';

export interface OperatorDef {
  value: string;
  label: string;
  needsValue: boolean;
}

export const STRING_OPERATORS: OperatorDef[] = [
  { value: 'eq', label: 'ist gleich', needsValue: true },
  { value: 'neq', label: 'ist ungleich', needsValue: true },
  { value: 'contains', label: 'enthält', needsValue: true },
  { value: 'not_contains', label: 'enthält nicht', needsValue: true },
  { value: 'empty', label: 'ist leer', needsValue: false },
  { value: 'not_empty', label: 'ist nicht leer', needsValue: false },
];

export const NUMBER_OPERATORS: OperatorDef[] = [
  { value: 'eq', label: '=', needsValue: true },
  { value: 'neq', label: '≠', needsValue: true },
  { value: 'lt', label: '<', needsValue: true },
  { value: 'lte', label: '≤', needsValue: true },
  { value: 'gt', label: '>', needsValue: true },
  { value: 'gte', label: '≥', needsValue: true },
];

export const DATE_OPERATORS: OperatorDef[] = [
  { value: 'eq', label: 'ist gleich', needsValue: true },
  { value: 'neq', label: 'ist ungleich', needsValue: true },
  { value: 'before', label: 'vor', needsValue: true },
  { value: 'after', label: 'nach', needsValue: true },
];

export const BOOLEAN_OPERATORS: OperatorDef[] = [
  { value: 'is_true', label: 'ist wahr', needsValue: false },
  { value: 'is_false', label: 'ist falsch', needsValue: false },
];

export const FILE_OPERATORS: OperatorDef[] = [
  { value: 'exists', label: 'vorhanden', needsValue: false },
  { value: 'not_exists', label: 'nicht vorhanden', needsValue: false },
  { value: 'not_empty', label: 'nicht leer', needsValue: false },
  { value: 'empty', label: 'ist leer', needsValue: false },
];

const ALL_OPERATORS: OperatorDef[] = [
  ...STRING_OPERATORS,
  ...NUMBER_OPERATORS,
  ...DATE_OPERATORS,
  ...BOOLEAN_OPERATORS,
  ...FILE_OPERATORS,
];

export function operatorsForType(t: FieldType): OperatorDef[] {
  if (t === 'string' || t === 'email') return STRING_OPERATORS;
  if (t === 'number') return NUMBER_OPERATORS;
  if (t === 'date') return DATE_OPERATORS;
  if (t === 'boolean') return BOOLEAN_OPERATORS;
  if (t === 'file') return FILE_OPERATORS;
  return ALL_OPERATORS;
}
