import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  EscrowListParams,
  EscrowListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const escrowList = (params: EscrowListParams) => {
  return resultify(
    axios.post<EscrowListResponse>(API_URL.escrowList(), params),
  );
};

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

  return {
    ...mutation,
  };
};
