/**
 * Modèles pour le système de filtres avancés
 */

export enum FilterOperator {
  // Texte
  CONTAINS = 'contains',
  NOT_CONTAINS = 'notContains',
  EQUALS = 'equals',
  NOT_EQUALS = 'notEquals',
  STARTS_WITH = 'startsWith',
  ENDS_WITH = 'endsWith',
  IS_EMPTY = 'isEmpty',
  IS_NOT_EMPTY = 'isNotEmpty',

  // Nombre
  GREATER_THAN = 'greaterThan',
  LESS_THAN = 'lessThan',
  GREATER_THAN_OR_EQUAL = 'greaterThanOrEqual',
  LESS_THAN_OR_EQUAL = 'lessThanOrEqual',
  BETWEEN = 'between',

  // Date
  DATE_EQUALS = 'dateEquals',
  DATE_BEFORE = 'dateBefore',
  DATE_AFTER = 'dateAfter',
  DATE_BETWEEN = 'dateBetween',
  LAST_N_DAYS = 'lastNDays',

  // Liste
  IN = 'in',
  NOT_IN = 'notIn'
}

export enum LogicalOperator {
  AND = 'ET',
  OR = 'OU'
}

export enum FieldType {
  TEXT = 'text',
  NUMBER = 'number',
  DATE = 'date',
  SELECT = 'select',
  BOOLEAN = 'boolean'
}

export interface FilterCondition {
  id: string;
  field: string;
  operator: FilterOperator;
  value: any;
  value2?: any; // Pour "between"
}

export interface FilterGroup {
  id: string;
  logicalOperator: LogicalOperator;
  conditions: (FilterCondition | FilterGroup)[];
}

export interface FieldDefinition {
  name: string;
  label: string;
  type: FieldType;
  operators: FilterOperator[];
  options?: { label: string; value: any }[];
}

export interface FilterRequest {
  filters?: FilterGroup | null;
  page: number;
  pageSize: number;
  sortBy?: string;
  sortOrder?: 'asc' | 'desc';
}

export interface FilterResponse<T> {
  data: T[];
  total: number;
  page: number;
  pageSize: number;
}
