import { regionQueryKeys } from '../regions-query-keys';
import { regionsApi, type PostGetMapDataReturn } from '../regions-api';
import { queryClient } from 'src/utils/queryClient';

export const fetchMapData = async (id: number) => {
  try {
    const data: PostGetMapDataReturn = await queryClient.fetchQuery({
      queryKey: regionQueryKeys.getMapData(),
      queryFn: async () => {
        const response = await regionsApi.getMapData(
          id,
        )
        return response.data;
      },
      gcTime: 0,
      staleTime: 0
    });

    return data;
  } catch (error) {
    console.error('Failed to fetch map data:', error);
  }
};