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

import { locationQueryKeys } from '../location-query-keys';
import { locationApi, type PostGetUsersLocationReturn } from '../location-api';

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

export const usePostGetUsersLocationQuery = (token: string, enabled: boolean) => {
  return useQuery<PostGetUsersLocationReturn, BaseAxiosError>({
    queryKey: locationQueryKeys.getUsersLocation(token),
    queryFn: async () => {
      const response = await locationApi.getUsersLocation(token);
      return response.data;
    },
    enabled
  });
};
