import { debounce } from "lodash";
import { SearchResultsStore } from "searchResults/domain/searchStore";

type ChangeRequestStore = Pick<
  SearchResultsStore,
  "changeSearchRequest" | "searchRequest"
>;

const debouncedTask = debounce((task) => Promise.resolve(task()), 200);

const changeSearchRequestUseCase = (store: ChangeRequestStore) => {
  return debouncedTask(() => store.changeSearchRequest(store.searchRequest));
};

export { changeSearchRequestUseCase };
