// imports

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

// types

export type DeleteAttachmentRequest = {
    id: number | string;
};

// methods

export const handleDeleteAttachment = async ({
    id,
}: DeleteAttachmentRequest) => {
    // state

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

    const { data } = await axios.delete(
        `${API_ENDPOINTS.tickets.delete_attachment}/${id}`
    );
    return data;
};

// composable

const useDeleteAttachment = () => {
    return useMutation({
        mutationFn: (data: DeleteAttachmentRequest) =>
            handleDeleteAttachment({ ...data }),
    });
};

export default useDeleteAttachment;
