/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { NoProviderError } from "../MatterError.js";
import { Environmental } from "../environment/Environmental.js";
import { Diagnostic } from "../log/Diagnostic.js";
import { StorageManager } from "./StorageManager.js";
class StorageService {
  #factory;
  #location;
  constructor(environment, factory, resolver) {
    environment.set(StorageService, this);
    this.#factory = factory;
    this.resolve = resolver ?? ((...paths) => paths.join("/"));
  }
  static [Environmental.create](environment) {
    return new this(environment);
  }
  /**
   * Open storage.  The storage is initialized but the caller must take ownership.
   *
   * @param namespace a unique namespace identifier such as a root node ID
   */
  async open(namespace) {
    if (this.#factory === void 0) {
      throw new NoProviderError("Storage is unavailable because no platform implementation is installed");
    }
    const storage = await this.#factory(namespace);
    const manager = new StorageManager(storage);
    await manager.initialize();
    return manager;
  }
  /**
   * Install a factory for opening storage.  Without such a factory storage is unavailable.
   */
  set factory(factory) {
    this.#factory = factory;
  }
  /**
   * The storage location.  Only used for diagnostic purposes.
   */
  get location() {
    return this.#location;
  }
  set location(location2) {
    this.#location = location2;
  }
  /**
   * Join one or more relative paths to some platform-dependent notion of an absolute storage path.
   */
  resolve;
  [Diagnostic.value]() {
    return [
      "Persistence",
      Diagnostic.dict({
        location: location ?? "(unknown)",
        available: !!this.#factory
      })
    ];
  }
}
export {
  StorageService
};
//# sourceMappingURL=StorageService.js.map
