import React from "react";
import { ServicesStore } from "services/domain/servicesStore";
import { loadServicesUseCase } from "services/useCases/loadServicesUseCase";
import { UIStore } from "ui/domain/uiStore";

function useServicesViewModel(store: ServicesStore & Pick<UIStore, "notify">) {
  const loadServices = React.useCallback(
    function () {
      loadServicesUseCase({
        loadServices: store.loadServices,
      });
    },
    [store.loadServices]
  );

  React.useEffect(() => {
    loadServices();
  }, [loadServices]);

  return {
    services: store.services,
    failure: store.failure,
    isLoading: store.isLoading,
    isFailed: store.isFailed,
    loadServices,
  };
}

export { useServicesViewModel };
