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

export const settlementsHistorySummary = (params: SettlementsHistorySummaryParams) => {
  return resultify(
    axios.post<SettlementsHistorySummaryResponse>(API_URL_SETTLEMENT.settlementsHistorySummary(), params),
  );
};

export const useSettlementsHistorySummaryMutation = (options?: UseMutationOptions<SettlementsHistorySummaryResponse, CBDCAxiosError, SettlementsHistorySummaryParams>) => {
  const mutation = useMutation<SettlementsHistorySummaryResponse, CBDCAxiosError, SettlementsHistorySummaryParams>({
    ...options,
    mutationFn: (params: SettlementsHistorySummaryParams) => settlementsHistorySummary(params),
  });

  return {
    ...mutation,
  };
};
