export enum InputType {
  Text = 1,
  Checkbox = 2,
  DateRange = 128,
  NumberRange = 4096,
}

/**
 * Enumeration of search trigger types that indicate how a search was initiated.
 * Used throughout the filter system to track user interaction patterns and
 * optimize search behavior based on the trigger source.
 *
 * @example
 * ```typescript
 * // Handle different search triggers
 * handleSearch(trigger: SearchTrigger) {
 *   switch(trigger) {
 *     case SearchTrigger.Input:
 *       // User typed or clicked search
 *       break;
 *     case SearchTrigger.Scan:
 *       // Barcode was scanned
 *       break;
 *   }
 * }
 * ```
 */
export const SearchTrigger = {
  /** User manually entered text or clicked the search button */
  Input: 'input',
  /** User applied or changed filter settings */
  Filter: 'filter',
  /** Barcode scanner provided input */
  Scan: 'scan',
  /** User changed the sort order */
  OrderBy: 'order-by',
} as const;

/**
 * Type representing the possible search trigger values.
 * Derived from the SearchTrigger const object to ensure type safety.
 */
export type SearchTrigger = (typeof SearchTrigger)[keyof typeof SearchTrigger];

export interface QuerySettings {
  /**
   * Filter
   */
  filter: Array<InputGroup>;

  /**
   * Eingabefelder
   */
  input: Array<InputGroup>;

  /**
   * Sortierung
   */
  orderBy: Array<OrderBy>;
}

export interface InputGroup {
  /**
   * Beschreibung
   */
  description?: string;

  /**
   * Group / ID
   */
  group: string;

  /**
   * Eingabefelder
   */
  input: Array<Input>;

  /**
   * Label
   */
  label?: string;
}

/**
 * Sortierwert
 */
export interface OrderBy {
  /**
   * Wert
   */
  by?: string;

  /**
   * Absteigend
   */
  desc?: boolean;

  /**
   * Label
   */
  label?: string;
}

/**
 * Eingabeelement
 */
export interface Input {
  /**
   * Regex-Überprüfung
   */
  constraint?: string;

  /**
   * Beschreibung
   */
  description?: string;

  /**
   * Key / ID
   */
  key: string;

  /**
   * Label
   */
  label?: string;

  /**
   * Max-Wert (optional)
   */
  maxValue?: string;

  /**
   * Min-Wert (optional)
   */
  minValue?: string;

  /**
   * Auswahl
   */
  options?: InputOptions;

  /**
   * Wasserzeichen
   */
  placeholder?: string;

  /**
   * Anwendungsziel
   */
  target?: string;

  /**
   * Art des Werts
   */
  type: InputType;

  /**
   * Wert
   */
  value?: string;
}

/**
 * Auswahl
 */
export interface InputOptions {
  /**
   * Maximale Anzahl auswählbarer Elemente (null => alle, 1 = single select)
   */
  max?: number;

  /**
   * Werte
   */
  values?: Array<Option>;
}

/**
 * Auswahlelement
 */
export interface Option {
  /**
   * Beschreibung
   */
  description?: string;

  /**
   * Aktiv
   */
  enabled?: boolean;

  /**
   * Key / ID
   */
  key?: string;

  /**
   * Label
   */
  label?: string;

  /**
   * Max-Wert (optional)
   */
  maxValue?: string;

  /**
   * Min-Wert (optional)
   */
  minValue?: string;

  /**
   * Wasserzeichen
   */
  placeholder?: string;

  /**
   * Ausgewählt / Default
   */
  selected?: boolean;

  /**
   * Wert
   */
  value?: string;

  /**
   * Unter-Optionen
   */
  values?: Array<Option>;
}
