// imports

import { useQuery } from "@tanstack/vue-query";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";

// types

export type GetCategoriesResponse = Category[];

const useGetCategories = () => {
    // state

    const { $axios: axios } = useNuxtApp();

    // methods

    const handleGetCategories = async () => {
        const { data } = await axios.get<GetCategoriesResponse>(
            `${API_ENDPOINTS.products.categories}`
        );

        return data;
    };

    return useQuery({
        queryKey: [QUERY_KEYS.categories],
        queryFn: () => handleGetCategories(),
    });
};

export default useGetCategories;
