import {GET_ROLE_LIST} from "@/core/data/apiRoutes";
import useRequest from "@/lib/app/hooks/useRequest";
import useSWR from "swr";

const useRole = () => {
    const requestServer = useRequest({auth: true, notification: false})

    //swr config
    const fetcher = (...args) => {
        return requestServer(args, 'get').then(({data}) => {
            return data.data;
        }).catch(() => {
        })
    };

    const {data, isLoading} = useSWR(GET_ROLE_LIST, fetcher, {
        revalidateIfStale: false,
        revalidateOnFocus: false,
        revalidateOnReconnect: false,
        keepPreviousData: true
    });

    return {
        roleList: data,
        isLoadingRoleList: isLoading,
        errorRoleList: !data
    }
};

export default useRole;