import { resultify } from "@/shared/lib/resultify";
import { ExtensionLInkPaySeparateActionParams, ExtensionLinkPaySeparateActionResponse } from "../../model/link-pay/types";
import axios from "axios";
import { API_URL_ADDITIONAL_SERVICE } from "@/shared/api/api-url-additional-service";
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
import { NiceAxiosError } from "@/shared/@types/error";
import { getHeaderUserAgent } from "@/shared/constants/url";

export const extensionLinkPaySeparateAction = (params: ExtensionLInkPaySeparateActionParams) => {
    let headerOptions = {
        menuId: 54,
        apiType: 'UPDATE'
    };
    let options = {
        headers: {
            'X-User-Agent': getHeaderUserAgent(headerOptions)
        }
    };
    return resultify(
        axios.post<ExtensionLinkPaySeparateActionResponse>(API_URL_ADDITIONAL_SERVICE.extensionLinkPaymentSeparateAction(), params, options)
    );
};

export const useExtensionLinkPaySeparateAction = (options?: UseMutationOptions<ExtensionLinkPaySeparateActionResponse, NiceAxiosError, ExtensionLInkPaySeparateActionParams>) => {
    const mutation = useMutation<ExtensionLinkPaySeparateActionResponse, NiceAxiosError, ExtensionLInkPaySeparateActionParams>({
        ...options,
        mutationFn: (params: ExtensionLInkPaySeparateActionParams) => extensionLinkPaySeparateAction(params),
    });

    return {
        ...mutation,
    };
};
