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

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

export const useFaqListMutation = (options?: UseMutationOptions<FaqListResponse, NiceAxiosError, FaqListParams>) => {
  const mutation = useMutation<FaqListResponse, NiceAxiosError, FaqListParams>({
    ...options,
    mutationFn: (params: FaqListParams) => faqList(params),
  });

  return {
    ...mutation,
  };
};
