import { useQuery, UseQueryOptions } from '@tanstack/react-query' import { analyticsKeys } from './keys' import { get, handleError } from 'data/fetchers' import { ResponseError } from 'types' export type WarehouseTenantVariables = { projectRef: string } export type WarehouseTenantResponse = any export async function getWarehouseTenant( { projectRef }: WarehouseTenantVariables, signal?: AbortSignal ) { if (!projectRef) { throw new Error('projectRef is required') } const { data, error } = await get(`/platform/projects/{ref}/analytics/warehouse/tenant`, { params: { path: { ref: projectRef } }, signal, }) if (error) { handleError(error) } return data } export type WarehouseTenantData = Awaited> export type WarehouseTenantError = ResponseError export const useWarehouseTenantQuery = ( { projectRef }: WarehouseTenantVariables, { enabled = true, ...options }: UseQueryOptions = {} ) => useQuery( analyticsKeys.warehouseTenant(projectRef), ({ signal }) => getWarehouseTenant({ projectRef }, signal), { enabled: enabled && !!projectRef, staleTime: Infinity, // 2H mins cache time cacheTime: 120 * 60 * 1000, refetchOnMount: false, refetchInterval: false, ...options, } )