/**
 * Configuration des opérateurs de filtres par type de champ
 */

import { FilterOperator, FieldType } from '../models/filter.models';

export const OPERATORS_BY_TYPE: Record<FieldType, FilterOperator[]> = {
  [FieldType.TEXT]: [
    FilterOperator.CONTAINS,
    FilterOperator.NOT_CONTAINS,
    FilterOperator.EQUALS,
    FilterOperator.NOT_EQUALS,
    FilterOperator.STARTS_WITH,
    FilterOperator.ENDS_WITH,
    FilterOperator.IS_EMPTY,
    FilterOperator.IS_NOT_EMPTY
  ],
  [FieldType.NUMBER]: [
    FilterOperator.EQUALS,
    FilterOperator.NOT_EQUALS,
    FilterOperator.GREATER_THAN,
    FilterOperator.LESS_THAN,
    FilterOperator.GREATER_THAN_OR_EQUAL,
    FilterOperator.LESS_THAN_OR_EQUAL,
    FilterOperator.BETWEEN,
    FilterOperator.IS_EMPTY,
    FilterOperator.IS_NOT_EMPTY
  ],
  [FieldType.DATE]: [
    FilterOperator.DATE_EQUALS,
    FilterOperator.DATE_BEFORE,
    FilterOperator.DATE_AFTER,
    FilterOperator.DATE_BETWEEN,
    FilterOperator.LAST_N_DAYS,
    FilterOperator.IS_EMPTY,
    FilterOperator.IS_NOT_EMPTY
  ],
  [FieldType.SELECT]: [
    FilterOperator.EQUALS,
    FilterOperator.NOT_EQUALS,
    FilterOperator.IN,
    FilterOperator.NOT_IN,
    FilterOperator.IS_EMPTY,
    FilterOperator.IS_NOT_EMPTY
  ],
  [FieldType.BOOLEAN]: [
    FilterOperator.EQUALS
  ]
};

export const OPERATOR_LABELS: Record<FilterOperator, string> = {
  [FilterOperator.CONTAINS]: 'contient',
  [FilterOperator.NOT_CONTAINS]: 'ne contient pas',
  [FilterOperator.EQUALS]: 'est égal à',
  [FilterOperator.NOT_EQUALS]: 'n\'est pas égal à',
  [FilterOperator.STARTS_WITH]: 'commence par',
  [FilterOperator.ENDS_WITH]: 'se termine par',
  [FilterOperator.IS_EMPTY]: 'est vide',
  [FilterOperator.IS_NOT_EMPTY]: 'n\'est pas vide',
  [FilterOperator.GREATER_THAN]: 'est supérieur à',
  [FilterOperator.LESS_THAN]: 'est inférieur à',
  [FilterOperator.GREATER_THAN_OR_EQUAL]: 'est supérieur ou égal à',
  [FilterOperator.LESS_THAN_OR_EQUAL]: 'est inférieur ou égal à',
  [FilterOperator.BETWEEN]: 'est entre',
  [FilterOperator.DATE_EQUALS]: 'date exacte',
  [FilterOperator.DATE_BEFORE]: 'est antérieur à',
  [FilterOperator.DATE_AFTER]: 'est postérieur à',
  [FilterOperator.DATE_BETWEEN]: 'est compris dans la période',
  [FilterOperator.LAST_N_DAYS]: 'est dans les derniers X jours',
  [FilterOperator.IN]: 'est l\'un de',
  [FilterOperator.NOT_IN]: 'n\'est aucun de'
};

// Opérateurs qui ne nécessitent pas de valeur
export const OPERATORS_WITHOUT_VALUE = [
  FilterOperator.IS_EMPTY,
  FilterOperator.IS_NOT_EMPTY
];

// Opérateurs qui nécessitent 2 valeurs
export const OPERATORS_WITH_TWO_VALUES = [
  FilterOperator.BETWEEN,
  FilterOperator.DATE_BETWEEN
];
