// imports

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

// types

export type SubscribeNotificationRequest = {
    body: PushSubscriptionJSON;
};

const useSubscribeNotification = () => {
    // state

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

    // methods

    const handleSubscribeNotification = async (
        params: SubscribeNotificationRequest
    ) => {
        const { data } = await axios.post(API_ENDPOINTS.account.subscribe, {
            ...params.body,
        });
        return data;
    };

    return useMutation({
        mutationFn: (subscribeData: SubscribeNotificationRequest) =>
            handleSubscribeNotification(subscribeData),
    });
};

export default useSubscribeNotification;
