import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  NoticeListParams,
  NoticeListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const noticeList = (params: NoticeListParams) => {
  return resultify(
    axios.post<NoticeListResponse>(API_URL.noticeList(), params),
  );
};

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

  return {
    ...mutation,
  };
};
