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

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

export const useEscrowListMutation = (options?: UseMutationOptions<EscrowListResponse, NiceAxiosError, EscrowListParams>) => {
  const mutation = useMutation<EscrowListResponse, NiceAxiosError, EscrowListParams>({
    ...options,
    mutationFn: (params: EscrowListParams) => escrowList(params),
  });

  return {
    ...mutation,
  };
};
