"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 StorageManager_exports = {};
__export(StorageManager_exports, {
  StorageManager: () => StorageManager
});
module.exports = __toCommonJS(StorageManager_exports);
var import_Promises = require("../util/Promises.js");
var import_StorageContext = require("./StorageContext.js");
var import_StorageDriver = require("./StorageDriver.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class StorageManager {
  #driver;
  #isInitialized = false;
  constructor(driver) {
    this.#driver = driver;
  }
  get driver() {
    return this.#driver;
  }
  get driverId() {
    return this.#driver.id;
  }
  initialize() {
    if (!this.#driver.initialized) {
      const init = this.#driver.initialize();
      if (import_Promises.MaybePromise.is(init)) {
        return init.then(() => {
          this.#isInitialized = true;
        });
      }
    }
    this.#isInitialized = true;
  }
  close() {
    this.#isInitialized = false;
    return this.#driver.close();
  }
  createContext(context) {
    if (!this.#isInitialized) {
      throw new import_StorageDriver.StorageError("The storage needs to be initialized first!");
    }
    if (!context.length) {
      throw new import_StorageDriver.StorageError("Context must not be an empty string!");
    }
    if (context.includes(".")) {
      throw new import_StorageDriver.StorageError("Context must not contain dots!");
    }
    return new import_StorageContext.StorageContext(this.#driver, [context]);
  }
}
//# sourceMappingURL=StorageManager.js.map
