// imports

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

// types

export type SubmitSpecialDiscountCodeRequest = {
    code: string;
};

const useSubmitSpecialDiscountCode = () => {
    // state

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

    // methods

    const handleSubmitSpecialDiscountCode = async (
        params: SubmitSpecialDiscountCodeRequest
    ) => {
        const { data } = await axios.post(
            API_ENDPOINTS.orders.cart.add_special_discount,
            {
                ...params,
            }
        );
        return data;
    };

    return useMutation({
        mutationFn: (discountData: SubmitSpecialDiscountCodeRequest) =>
            handleSubmitSpecialDiscountCode(discountData),
    });
};

export default useSubmitSpecialDiscountCode;
