import { resultify } from "@/shared/lib/resultify";
import { ExtensionFundAccountTransferRequestParams, ExtensionFundAccountTransferRequestResponse } from "../../model/fund-account/types";
import { API_URL_ADDITIONAL_SERVICE } from "@/shared/api/api-url-additional-service";
import axios from "axios";
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
import { NiceAxiosError } from "@/shared/@types/error";
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionFundAccountTransferRequest = (params: ExtensionFundAccountTransferRequestParams) => {
    let headerOptions = {
        menuId: 55,
        apiType: 'UPDATE'
    };
    let options = {
        headers: {
            'X-User-Agent': getHeaderUserAgent(headerOptions)
        }
    };
    return resultify(
        axios.post<ExtensionFundAccountTransferRequestResponse>(API_URL_ADDITIONAL_SERVICE.extensionFundAccountTransferRequest(), params, options),
    );
};

export const useExtensionFundAccountTransferRequestMutation = (options?: UseMutationOptions<ExtensionFundAccountTransferRequestResponse, NiceAxiosError, ExtensionFundAccountTransferRequestParams>) => {
    const mutation = useMutation<ExtensionFundAccountTransferRequestResponse, NiceAxiosError, ExtensionFundAccountTransferRequestParams>({
        ...options,
        mutationFn: (params: ExtensionFundAccountTransferRequestParams) => extensionFundAccountTransferRequest(params),
    });

    return {
        ...mutation,
    };
};