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

export const homeToday = (params: HomeTodayParams) => {
  return resultify(
    axios.post<HomeTodayResponse>(API_URL_HOME.homeToday(), params),
  );
};

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

  return {
    ...mutation,
  };
};
