import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
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_TRANSACTION.escrowDetail(), params),
  );
};

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

  return {
    ...mutation,
  };
};
