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

export const homeBannerList = (params: HomeBannerListParams) => {
  return resultify(
    axios.post<HomeBannerListResponse>(API_URL_HOME.homeBannerList(), params),
  );
};

export const useHomeBannerListMutation = (options?: UseMutationOptions<HomeBannerListResponse, CBDCAxiosError, HomeBannerListParams>) => {
  const mutation = useMutation<HomeBannerListResponse, CBDCAxiosError, HomeBannerListParams>({
    ...options,
    mutationFn: (params: HomeBannerListParams) => homeBannerList(params),
  });

  return {
    ...mutation,
  };
};
