import axios from 'axios';
import { API_URL_SETTLEMENT } from '@/shared/api/api-url-settlement';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  SettlementsTransactionDetailParams,
  SettlementsTransactionDetailResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const settlementsTransactionDetail = (params: SettlementsTransactionDetailParams) => {
  return resultify(
    axios.post<SettlementsTransactionDetailResponse>(API_URL_SETTLEMENT.settlementsTransactionDetail(), params),
  );
};

export const useSettlementsTransactionDetailMutation = (options?: UseMutationOptions<SettlementsTransactionDetailResponse, CBDCAxiosError, SettlementsTransactionDetailParams>) => {
  const mutation = useMutation<SettlementsTransactionDetailResponse, CBDCAxiosError, SettlementsTransactionDetailParams>({
    ...options,
    mutationFn: (params: SettlementsTransactionDetailParams) => settlementsTransactionDetail(params),
  });

  return {
    ...mutation,
  };
};
