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

export const homeNoticeList = (params: HomeNoticeListParams) => {
  let headerOptions = {
    menuId: 0,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<HomeNoticeListResponse>(API_URL_HOME.homeBannerList(), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
