// imports

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

// types

export type GetCommentsResponse = ApiPaginated<UserComment>;

const useGetComments = (id: string | number | undefined, page: Ref<number>) => {

    // state

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

    // methods

    const handleGetComments = async () => {
        const { data } = await axios.get<GetCommentsResponse>(`${API_ENDPOINTS.product.comments}/${id}`);
        return data;
    };

    return useQuery({
        queryKey: [QUERY_KEYS.comments, id, page],
        queryFn: () => handleGetComments()
    });
};

export default useGetComments;
