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

export const settlementsTransactionList = (params: SettlementsTransactionListParams) => {
  return resultify(
    axios.post<SettlementsTransactionListResponse>(API_URL_SETTLEMENT.settlementsTransactionList(), params),
  );
};

export const useSettlementsTransactionListMutation = (options?: UseMutationOptions<SettlementsTransactionListResponse, CBDCAxiosError, SettlementsTransactionListParams>) => {
  const mutation = useMutation<SettlementsTransactionListResponse, CBDCAxiosError, SettlementsTransactionListParams>({
    ...options,
    mutationFn: (params: SettlementsTransactionListParams) => settlementsTransactionList(params),
  });

  return {
    ...mutation,
  };
};
