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

export const homeOverview = (params: HomeOverviewParams) => {
  return resultify(
    axios.post<HomeOverviewResponse>(API_URL_HOME.homeOverview(), params),
  );
};

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

  return {
    ...mutation,
  };
};
