import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  ExtensionPayoutRequestParams,
  ExtensionPayoutRequestResponse
} from '../../model/payout/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const extensionPayoutRequest = (params: ExtensionPayoutRequestParams) => {
  return resultify(
    axios.post<ExtensionPayoutRequestResponse>(API_URL_ADDITIONAL_SERVICE.extensionPayoutRequest(), params),
  );
};

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

  return {
    ...mutation,
  };
};
