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 {
  ExtensionPayoutRequestParams,
  ExtensionPayoutRequestResponse
} from '../../model/payout/types';
import {
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionPayoutRequest = (params: ExtensionPayoutRequestParams) => {
  let headerOptions = {
    menuId: 53,
    apiType: 'INSERT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ExtensionPayoutRequestResponse>(API_URL_ADDITIONAL_SERVICE.extensionPayoutRequest(), params, options),
  );
};

export const useExtensionPayoutRequestMutation = (options?: UseMutationOptions<ExtensionPayoutRequestResponse, NiceAxiosError, ExtensionPayoutRequestParams>) => {
  const mutation = useMutation<ExtensionPayoutRequestResponse, NiceAxiosError, ExtensionPayoutRequestParams>({
    ...options,
    mutationFn: (params: ExtensionPayoutRequestParams) => extensionPayoutRequest(params),
  });

  return {
    ...mutation,
  };
};
