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

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

export const useHomeTodayMutation = (options?: UseMutationOptions<HomeTodayResponse, NiceAxiosError, HomeTodayParams>) => {
  const mutation = useMutation<HomeTodayResponse, NiceAxiosError, HomeTodayParams>({
    ...options,
    mutationFn: (params: HomeTodayParams) => homeToday(params),
  });

  return {
    ...mutation,
  };
};
