// imports

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

// types

export type DeleteCartItemRequest = {
    id: number;
};

const useDeleteCartItem = () => {
    // state

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

    // methods

    const handleDeleteCartItem = async (id: number) => {
        const { data } = await axios.delete(
            `${API_ENDPOINTS.orders.cart.delete_one}/${id}`
        );
        return data;
    };

    return useMutation({
        mutationFn: (data: DeleteCartItemRequest) =>
            handleDeleteCartItem(data.id),
    });
};

export default useDeleteCartItem;
