import { Input, InputType } from '../../types';
import { FilterInput } from '../schemas';
import { checkboxFilterInputMapping } from './checkbox-filter-input.mapping';
import { dateRangeFilterInputMapping } from './date-range-filter-input.mapping';
import { numberRangeFilterInputMapping } from './number-range-filter-input.mapping';
import { textFilterInputMapping } from './text-filter-input.mapping';

/**
 * Maps an Input object to the appropriate FilterInput type based on its input type
 *
 * This function serves as a router that delegates to the specific mapping function
 * based on the input type (Text, Checkbox, DateRange). It ensures that each input
 * is converted to its corresponding strongly-typed filter input object.
 *
 * @param group - The group identifier that this input belongs to
 * @param input - The source input object to map
 * @returns A validated FilterInput object of the appropriate subtype
 * @throws Error if the input type is not supported
 */
export function filterInputMapping(group: string, input: Input): FilterInput {
  switch (input.type) {
    case InputType.Text:
      return textFilterInputMapping(group, input);
    case InputType.Checkbox:
      return checkboxFilterInputMapping(group, input);
    case InputType.DateRange:
      return dateRangeFilterInputMapping(group, input);
    case InputType.NumberRange:
      return numberRangeFilterInputMapping(group, input);
  }
  console.warn('filterInputMapping: Unknown input type', input);
}
