import { Input, InputType } from '../../types';
import { DateRangeFilterInput, DateRangeFilterInputSchema } from '../schemas';

/**
 * Maps an Input object to a DateRangeFilterInput object
 *
 * This function takes an input of type DateRange and maps it to a strongly-typed
 * DateRangeFilterInput object, validating it against a schema. It extracts the start
 * and stop dates from the input's option values.
 *
 * @param group - The group identifier that this input belongs to
 * @param input - The source input object to map
 * @returns A validated DateRangeFilterInput object
 */
export function dateRangeFilterInputMapping(
  group: string,
  input: Input,
): DateRangeFilterInput {
  return DateRangeFilterInputSchema.parse({
    group,
    key: input.key,
    label: input.label,
    description: input.description,
    target: input.target,
    type: InputType.DateRange,
    start: input.options?.values?.[0]?.value,
    stop: input.options?.values?.[1]?.value,
    minStart: input.options?.values?.[0]?.minValue,
    maxStop: input.options?.values?.[0]?.maxValue,
  });
}
