import { appQueryKeys } from '../app-query-keys';
import { type PostGetLastUpdate, appApi } from '../app-api';
import { queryClient } from 'src/utils/queryClient';

export const fetchLastRegionsDbUpdate = async (date: string) => {
  try {
    const data: PostGetLastUpdate = await queryClient.fetchQuery({
      queryKey: appQueryKeys.getLastRegionsUpdate(),
      queryFn: async () => {
        const response = await appApi.getLastRegionsUpdate(date);
        return response.data;
      },
      gcTime: 0,
      staleTime: 0
    });

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