import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  AllTransactionCancelInfoParams,
  AllTransactionCancelInfoResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const allTransactionCancelInfo = (params: AllTransactionCancelInfoParams) => {
  let headerOptions = {
    menuId: 31,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<AllTransactionCancelInfoResponse>(API_URL_TRANSACTION.allTransactionCancelInfo(), params, options),
  );
};

export const useAllTransactioCancleInfoMutation = (options?: UseMutationOptions<AllTransactionCancelInfoResponse, NiceAxiosError, AllTransactionCancelInfoParams>) => {
  const mutation = useMutation<AllTransactionCancelInfoResponse, NiceAxiosError, AllTransactionCancelInfoParams>({
    ...options,
    mutationFn: (params: AllTransactionCancelInfoParams) => allTransactionCancelInfo(params),
  });

  return {
    ...mutation,
  };
};
