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

export const settlementsTransactionSummary = (params: SettlementsTransactionSummaryParams) => {
  return resultify(
    axios.post<SettlementsTransactionSummaryResponse>(API_URL_SETTLEMENT.settlementsTransactionSummary(), params),
  );
};

export const useSettlementsTransactionSummaryMutation = (options?: UseMutationOptions<SettlementsTransactionSummaryResponse, CBDCAxiosError, SettlementsTransactionSummaryParams>) => {
  const mutation = useMutation<SettlementsTransactionSummaryResponse, CBDCAxiosError, SettlementsTransactionSummaryParams>({
    ...options,
    mutationFn: (params: SettlementsTransactionSummaryParams) => settlementsTransactionSummary(params),
  });

  return {
    ...mutation,
  };
};
