import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  AllTransactionListParams,
  AllTransactionListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const allTransactionList = (params: AllTransactionListParams) => {
  return resultify(
    axios.post<AllTransactionListResponse>(API_URL.allTransactionList(), params),
  );
};

export const useAllTransactionListMutation = (options?: UseMutationOptions<AllTransactionListResponse, CBDCAxiosError, AllTransactionListParams>) => {
  const mutation = useMutation<AllTransactionListResponse, CBDCAxiosError, AllTransactionListParams>({
    ...options,
    mutationFn: (params: AllTransactionListParams) => allTransactionList(params),
  });

  return {
    ...mutation,
  };
};
