import axios from 'axios';
import { API_URL_SUPPORT } from '@/shared/api/api-url-support';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  NoticeDetailParams,
  NoticeDetailResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const noticeDetail = (params: NoticeDetailParams) => {
  return resultify(
    axios.post<NoticeDetailResponse>(API_URL_SUPPORT.noticeDetail(), params),
  );
};

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

  return {
    ...mutation,
  };
};
