import type { AsyncData } from '#app'
import { useEnumManager } from '~/composables/data/useEnumManager'
import type { Enum } from '~/types/data'

interface useEnumFetchReturnType {
  fetch: (enumName: string) => AsyncData<Enum, null | true | Error>
}

export const useEnumFetch = (lazy: boolean = false): useEnumFetchReturnType => {
  const { enumManager } = useEnumManager()

  const fetch = (enumName: string) =>
    useAsyncData(enumName, () => enumManager.fetch(enumName), { lazy })

  // @ts-ignore
  return { fetch }
}
