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

export const settlementsHistory = (params: SettlementsHistoryParams) => {
  return resultify(
    axios.post<SettlementsHistoryResponse>(API_URL_SETTLEMENT.settlementsHistory(), params),
  );
};

export const useSettlementsHistoryMutation = (options?: UseMutationOptions<SettlementsHistoryResponse, CBDCAxiosError, SettlementsHistoryParams>) => {
  const mutation = useMutation<SettlementsHistoryResponse, CBDCAxiosError, SettlementsHistoryParams>({
    ...options,
    mutationFn: (params: SettlementsHistoryParams) => settlementsHistory(params),
  });

  return {
    ...mutation,
  };
};
