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

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

export const useExtensionLinkPayHistoryResendMutation = (options?: UseMutationOptions<ExtensionLinkPayHistoryResendResponse, NiceAxiosError, ExtensionLinkPayHistoryResendParams>) => {
    const mutation = useMutation<ExtensionLinkPayHistoryResendResponse, NiceAxiosError, ExtensionLinkPayHistoryResendParams>({
        ...options,
        mutationFn: (params: ExtensionLinkPayHistoryResendParams) => extensionLinkPayHistoryResend(params),
    });

    return {
        ...mutation,
    };
};