import axios from 'axios';
import { API_URL_HOME } from '@/shared/api/api-url-home';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  HomeNoticeListParams,
  HomeNoticeListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const homeNoticeList = (params: HomeNoticeListParams) => {
  return resultify(
    axios.post<HomeNoticeListResponse>(API_URL_HOME.homeBannerList(), params),
  );
};

export const useHomeBannerListMutation = (options?: UseMutationOptions<HomeNoticeListResponse, CBDCAxiosError, HomeNoticeListParams>) => {
  const mutation = useMutation<HomeNoticeListResponse, CBDCAxiosError, HomeNoticeListParams>({
    ...options,
    mutationFn: (params: HomeNoticeListParams) => homeNoticeList(params),
  });

  return {
    ...mutation,
  };
};
