import axios from 'axios';
import { API_URL_SUPPORT } from '@/shared/api/api-url-support';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  QnaListParams,
  QnaListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const qnaList = (params: QnaListParams) => {
  let headerOptions = {
    menuId: 64,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<QnaListResponse>(API_URL_SUPPORT.qnaList(), params, options),
  );
};

export const useQnaListMutation = (options?: UseMutationOptions<QnaListResponse, NiceAxiosError, QnaListParams>) => {
  const mutation = useMutation<QnaListResponse, NiceAxiosError, QnaListParams>({
    ...options,
    mutationFn: (params: QnaListParams) => qnaList(params),
  });

  return {
    ...mutation,
  };
};
