"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var StorageService_exports = {};
__export(StorageService_exports, {
  StorageService: () => StorageService
});
module.exports = __toCommonJS(StorageService_exports);
var import_MatterError = require("../MatterError.js");
var import_Environmental = require("../environment/Environmental.js");
var import_Diagnostic = require("../log/Diagnostic.js");
var import_StorageManager = require("./StorageManager.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class StorageService {
  #factory;
  #location;
  constructor(environment, factory, resolver) {
    environment.set(StorageService, this);
    this.#factory = factory;
    this.resolve = resolver ?? ((...paths) => paths.join("/"));
  }
  static [import_Environmental.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 import_MatterError.NoProviderError("Storage is unavailable because no platform implementation is installed");
    }
    const storage = await this.#factory(namespace);
    const manager = new import_StorageManager.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;
  [import_Diagnostic.Diagnostic.value]() {
    return [
      "Persistence",
      import_Diagnostic.Diagnostic.dict({
        location: location ?? "(unknown)",
        available: !!this.#factory
      })
    ];
  }
}
//# sourceMappingURL=StorageService.js.map
