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 { 
  SettlementsHistoryDetailParams,
  SettlementsHistoryDetailResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const settlementsHistoryDetail = (params: SettlementsHistoryDetailParams) => {
  return resultify(
    axios.post<SettlementsHistoryDetailResponse>(API_URL_SETTLEMENT.settlementsHistoryDetail(), params),
  );
};

export const useSettlementsHistoryDetailMutation = (options?: UseMutationOptions<SettlementsHistoryDetailResponse, CBDCAxiosError, SettlementsHistoryDetailParams>) => {
  const mutation = useMutation<SettlementsHistoryDetailResponse, CBDCAxiosError, SettlementsHistoryDetailParams>({
    ...options,
    mutationFn: (params: SettlementsHistoryDetailParams) => settlementsHistoryDetail(params),
  });

  return {
    ...mutation,
  };
};
