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 { 
  AllTransactionListParams,
  AllTransactionListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

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

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

  return {
    ...mutation,
  };
};
