/**
 * IRecordStoreProvider — pluggable per-package record-store factory.
 *
 * The runtime registers an implementation on the root context via
 * RECORD_STORE_PROVIDER_KEY. PackageRootActor reads the provider from its
 * cascading context and asks for a per-package store at bootstrap time. The
 * provider returns whatever value the consumer of RECORD_STORE_KEY expects
 * (today: a database handle; tomorrow: an IRecordStore wrapper or null).
 *
 * Core declares the seam. Implementations live in their own packages
 * (e.g., @open-matrix/system-sqlite). Core never imports a sibling
 * implementation package.
 */

export interface IRecordStoreProvider {
  /**
   * Produce a per-package record store, or return null if unavailable.
   *
   * Same observable contract as the legacy inline sqlite call inside
   * PackageRootActor: same matrixHome resolution, same domain key, same
   * eventual setService(RECORD_STORE_KEY, value) value shape.
   *
   * Implementations must not throw for "no backend available" cases —
   * return null and let PackageRootActor swallow it identically to the
   * pre-seam behavior.
   */
  provide(matrixHome: string, domain: string): Promise<unknown | null>;
}

/**
 * Service-registry key for the IRecordStoreProvider. The runtime registers
 * the implementation under this key on the root context; PackageRootActor
 * reads it via context.getService(RECORD_STORE_PROVIDER_KEY).
 */
export const RECORD_STORE_PROVIDER_KEY = Symbol.for('matrix.record-store.provider');
