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

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

export const useHomeOverviewMutation = (options?: UseMutationOptions<HomeOverviewResponse, NiceAxiosError, HomeOverviewParams>) => {
  const mutation = useMutation<HomeOverviewResponse, NiceAxiosError, HomeOverviewParams>({
    ...options,
    mutationFn: (params: HomeOverviewParams) => homeOverview(params),
  });

  return {
    ...mutation,
  };
};
