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

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

export const useAllTransactioCancleMutation = (options?: UseMutationOptions<AllTransactionCancelResponse, NiceAxiosError, AllTransactionCancelParams>) => {
  const mutation = useMutation<AllTransactionCancelResponse, NiceAxiosError, AllTransactionCancelParams>({
    ...options,
    mutationFn: (params: AllTransactionCancelParams) => allTransactionCancel(params),
  });

  return {
    ...mutation,
  };
};
