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

import { tripsQueryKeys } from '../trips-query-keys';
import { tripsApi, type PostGetTripsForRegionReturn } from '../trips-api';

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

export const useGetTripsForRegionQuery = (token: string, region: number, enabled: boolean) => {
  return useQuery<PostGetTripsForRegionReturn, BaseAxiosError>({
    queryKey: tripsQueryKeys.getTripsForRegion(token, region),
    queryFn: async () => {
      const response = await tripsApi.getTripsForRegion(token, region);
      return response.data;
    },
    enabled
  });
};
