import {
  VueQueryPlugin,
  QueryClient,
  type VueQueryPluginOptions
} from '@tanstack/vue-query';
import type { App } from 'vue';

// 创建一个 QueryClient 实例
export const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnWindowFocus: false,
      retry: false,
      staleTime: 1000 * 60 * 5 // 5 分钟
    }
  }
});

// 插件配置
export const vueQueryPluginOptions: VueQueryPluginOptions = {
  queryClient
};

// 导出插件安装函数
export function setupTanstackQuery(app: App) {
  app.use(VueQueryPlugin, vueQueryPluginOptions);
}
