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

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

export const useAllTransactionDetailMutation = (options?: UseMutationOptions<DetailResponse, NiceAxiosError, AllTransactionDetailParams>) => {
  const mutation = useMutation<DetailResponse, NiceAxiosError, AllTransactionDetailParams>({
    ...options,
    mutationFn: (params: AllTransactionDetailParams) => allTransactionDetail(params),
  });

  return {
    ...mutation,
  };
};
