import { useQuery } from '@tanstack/react-query' import { components } from 'api-types' import { projectKeys } from './keys' import { get, handleError } from '@/data/fetchers' import type { ResponseError, UseCustomQueryOptions } from '@/types' export type CloneStatus = components['schemas']['ProjectClonedStatusResponse_Output'] export async function getCloneStatus(projectRef?: string) { if (!projectRef) throw new Error('Project ref is required') const { data, error } = await get(`/platform/database/{ref}/clone/status`, { params: { path: { ref: projectRef } }, }) if (error) handleError(error) return data } export type CloneStatusData = Awaited> export type CloneStatusError = ResponseError export const useCloneStatusQuery = ( { projectRef }: { projectRef?: string }, options: UseCustomQueryOptions = {} ) => { return useQuery({ queryKey: projectKeys.listCloneStatus(projectRef), queryFn: () => getCloneStatus(projectRef), enabled: !!projectRef, ...options, }) }