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 { ExtensionLinkPayWaitDownloadExcelParams, ExtensionLinkPayWaitDownloadExcelRespone } from '../../model/link-pay/types';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionLinkPayWaitDownloadExcel = (params: ExtensionLinkPayWaitDownloadExcelParams) => {
    let headerOptions = {
        menuId: 54,
        apiType: 'SELECT'
    };
    let options = {
        headers: {
            'X-User-Agent': getHeaderUserAgent(headerOptions)
        }
    };
    return resultify(
        axios.post<ExtensionLinkPayWaitDownloadExcelRespone>(API_URL_ADDITIONAL_SERVICE.extensionLinkPaymentHistoryDownloadExcel(), params, options),
    );
};

export const useExtensionLinkPayWaitDownloadExcelMutation = (options?: UseMutationOptions<ExtensionLinkPayWaitDownloadExcelRespone, NiceAxiosError, ExtensionLinkPayWaitDownloadExcelParams>) => {
    const mutation = useMutation<ExtensionLinkPayWaitDownloadExcelRespone, NiceAxiosError, ExtensionLinkPayWaitDownloadExcelParams>({
        ...options,
        mutationFn: (params: ExtensionLinkPayWaitDownloadExcelParams) => extensionLinkPayWaitDownloadExcel(params),
    });

    return {
        ...mutation,
    };
};