/**
 * Thin shim over rSpace's local-first storage for markwhen source adapters.
 *
 * Keeps adapters free of direct dependencies on the concrete storage class,
 * so they remain unit-testable with plain in-memory docs. Wire the real
 * implementation in server/local-first at bootstrap via `setDocLoader`.
 */

export interface DocLoader {
	loadDoc<T>(docId: string): Promise<T | null>;
	listDocIds(prefix: string): Promise<string[]>;
}

let impl: DocLoader | null = null;

export function setDocLoader(loader: DocLoader): void {
	impl = loader;
}

export async function loadDoc<T>(docId: string): Promise<T | null> {
	if (!impl) throw new Error('markwhen doc-loader not wired — call setDocLoader at bootstrap');
	return impl.loadDoc<T>(docId);
}

export async function listDocIds(prefix: string): Promise<string[]> {
	if (!impl) throw new Error('markwhen doc-loader not wired — call setDocLoader at bootstrap');
	return impl.listDocIds(prefix);
}
