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

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

export const useNoticeListMutation = (options?: UseMutationOptions<NoticeListResponse, NiceAxiosError, NoticeListParams>) => {
  const mutation = useMutation<NoticeListResponse, NiceAxiosError, NoticeListParams>({
    ...options,
    mutationFn: (params: NoticeListParams) => noticeList(params),
  });

  return {
    ...mutation,
  };
};
