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

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

export const useNoticeDetailMutation = (options?: UseMutationOptions<NoticeDetailResponse, NiceAxiosError, NoticeDetailParams>) => {
  const mutation = useMutation<NoticeDetailResponse, NiceAxiosError, NoticeDetailParams>({
    ...options,
    mutationFn: (params: NoticeDetailParams) => noticeDetail(params),
  });

  return {
    ...mutation,
  };
};
