import {QUERY_TYPE} from "~/types/enums";
import { useFetch, computed } from '@nuxtjs/composition-api'
import DataProvider from "~/services/data/dataProvider";
import {repositoryHelper} from "~/services/store/repository";
import {TypeOfPractice} from "~/models/Organization/TypeOfPractice";

/**
 * @category composables/data
 * @class UseTypeOfPractice
 * Composable qui va récupérer les UseTypeOfPractices
 */
export function useTypeOfPracticeProvider($dataProvider: DataProvider){
  const {fetch, fetchState} = useFetch(async () => {
    await $dataProvider.invoke({
      type: QUERY_TYPE.MODEL,
      model: TypeOfPractice
    })
  })

  const typeOfPractices =  computed(() => {
    return repositoryHelper.findCollectionFromModel(TypeOfPractice)
  })

  return {
    typeOfPractices,
    fetch,
    fetchState
  }
}
