import {useEnumManager} from "~/composables/data/useEnumManager";
import {Enum} from "~/types/data";
import {AsyncData} from "#app";

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 }
}
