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

export const escrowDetail = (params: EscrowDetailParams) => {
  return resultify(
    axios.post<DetailResponse>(API_URL.escrowDetail(), params),
  );
};

export const useEscrowDetailMutation = (options?: UseMutationOptions<DetailResponse, CBDCAxiosError, EscrowDetailParams>) => {
  const mutation = useMutation<DetailResponse, CBDCAxiosError, EscrowDetailParams>({
    ...options,
    mutationFn: (params: EscrowDetailParams) => escrowDetail(params),
  });

  return {
    ...mutation,
  };
};
