import { debounce } from "lodash";
import { SubscriptionsStore } from "subscriptions/domain/subscriptionsStore";

const deboucedTask = debounce((task) => Promise.resolve(task()), 500);

type LoadSubscriptionsStore = Pick<SubscriptionsStore, "get">;

const getSubscriptionsUseCase = (store: LoadSubscriptionsStore) => {
  return deboucedTask(() => store.get());
};

export { getSubscriptionsUseCase };
