import { useMutation } from '@tanstack/react-query';
import { useQuery } from '@tanstack/react-query';

import { eventsQueryKeys } from '../events-query-keys';
import { type PostGetPhotosForRegionReturn, eventsApi } from '../events-api';

import type { BaseAxiosError } from '../../../../types';

export const usePostGetPhotosForRegionMutation = () => {
  return useMutation<
    PostGetPhotosForRegionReturn,
    BaseAxiosError,
    { region_id: number },
    PostGetPhotosForRegionReturn
  >({
    mutationKey: eventsQueryKeys.getPhotosForRegion(),
    mutationFn: async (variables) => {
      const response = await eventsApi.getPhotosForRegion(variables.region_id);
      return response.data;
    }
  });
};

export const useGetPhotosForRegionQuery = (region_id: number, enabled: boolean) => {
  return useQuery<PostGetPhotosForRegionReturn, BaseAxiosError>({
    queryKey: eventsQueryKeys.getPhotosForRegionQuery(region_id),
    queryFn: async () => {
      const response = await eventsApi.getPhotosForRegion(region_id);
      return response.data;
    },
    enabled
  });
};
