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

export const homeGroups = (params: HomeGroupsParams) => {
  return resultify(
    axios.post<HomeGroupsResponse>(API_URL_HOME.homeGroups(), params),
  );
};

export const useHomeGroupsMutation = (options?: UseMutationOptions<HomeGroupsResponse, CBDCAxiosError, HomeGroupsParams>) => {
  const mutation = useMutation<HomeGroupsResponse, CBDCAxiosError, HomeGroupsParams>({
    ...options,
    mutationFn: (params: HomeGroupsParams) => homeGroups(params),
  });

  return {
    ...mutation,
  };
};
