// imports

import { useMutation } from "@tanstack/vue-query";
import { API_ENDPOINTS } from "~/constants";

// types

export type CreateCommentRequest = {
    content: string;
};

const useCreateComment = (id: number | string | undefined) => {
    // state

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

    // methods

    const handleCreateComment = async (variables: CreateCommentRequest) => {
        const { data } = await axios.post(
            `${API_ENDPOINTS.product.create_comment}/${id}`,
            variables
        );
        return data;
    };

    return useMutation({
        mutationFn: (variables: CreateCommentRequest) =>
            handleCreateComment(variables),
    });
};

export default useCreateComment;
