import { Settings } from 'luxon';
import { describe, expect, it } from 'vitest';
import { FilterValues } from '../Filters.model';
import { createNumberRangeFilterValidators } from './NumberRangeFilterValidator';

interface NumberRangeFilterValidatorTestData {
  duration: number;
}

const defaultFilters: FilterValues<NumberRangeFilterValidatorTestData> = {
  duration: [10, 20],
};

describe('createNumberRangeFilterValidators', () => {
  Settings.defaultLocale = navigator.language;

  it('should return two functions', () => {
    const result =
      createNumberRangeFilterValidators<NumberRangeFilterValidatorTestData>();
    expect(Array.isArray(result)).toBeTruthy();
    expect(result).toHaveLength(2);
  });

  it('should validate From and To values correctly', () => {
    const [createFromValidator, createToValidator] =
      createNumberRangeFilterValidators<NumberRangeFilterValidatorTestData>();

    expect(createFromValidator('duration')(5, defaultFilters)).toBeUndefined();
    expect(createFromValidator('duration')(30, defaultFilters)).toBeDefined();
    expect(createToValidator('duration')(30, defaultFilters)).toBeUndefined();
    expect(createToValidator('duration')(5, defaultFilters)).toBeDefined();
  });

  it('should accept and apply options parameters', () => {
    const [createFromValidator, createToValidator] =
      createNumberRangeFilterValidators<NumberRangeFilterValidatorTestData>({
        fromIndex: 1,
        toIndex: 0,
      });

    const filters: FilterValues<NumberRangeFilterValidatorTestData> = {
      duration: [20, 10],
    };

    expect(createFromValidator('duration')(5, filters)).toBeUndefined();
    expect(createToValidator('duration')(30, filters)).toBeUndefined();
  });
});
