// imports

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

// types

export type AddCartItemRequest = {
    id: number;
    quantity: number;
};

const useAddCartItem = () => {
    // state

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

    // methods

    const handleAddCartItem = async (params: AddCartItemRequest) => {
        const { data } = await axios.post(
            `${API_ENDPOINTS.orders.cart.add_one}/${params.id}`,
            {
                quantity: params.quantity,
            }
        );
        return data;
    };

    return useMutation({
        mutationFn: (itemData: AddCartItemRequest) =>
            handleAddCartItem(itemData),
    });
};

export default useAddCartItem;
