import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  AllTransactionListSummaryParams,
  AllTransactionListSummaryResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const allTransactionListSummary = (params: AllTransactionListSummaryParams) => {
  let headerOptions = {
    menuId: 31,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<AllTransactionListSummaryResponse>(API_URL_TRANSACTION.allTransactionListSummary(), params, options),
  );
};

export const useAllTransactionListSummaryMutation = (options?: UseMutationOptions<AllTransactionListSummaryResponse, NiceAxiosError, AllTransactionListSummaryParams>) => {
  const mutation = useMutation<AllTransactionListSummaryResponse, NiceAxiosError, AllTransactionListSummaryParams>({
    ...options,
    mutationFn: (params: AllTransactionListSummaryParams) => allTransactionListSummary(params),
  });

  return {
    ...mutation,
  };
};
