"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 MockStorageService_exports = {};
__export(MockStorageService_exports, {
  MockStorageService: () => MockStorageService
});
module.exports = __toCommonJS(MockStorageService_exports);
var import_MatterError = require("#MatterError.js");
var import_MemoryBlobStorageDriver = require("./MemoryBlobStorageDriver.js");
var import_MemoryStorageDriver = require("./MemoryStorageDriver.js");
var import_StorageManager = require("./StorageManager.js");
var import_StorageService = require("./StorageService.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class MockStorageService extends import_StorageService.StorageService {
  #opener;
  #stores = /* @__PURE__ */ new Map();
  constructor(environment, opener) {
    super(environment);
    this.#opener = opener;
    this.registerBlobDriver({
      id: import_MemoryBlobStorageDriver.MemoryBlobStorageDriver.id,
      create: () => new import_MemoryBlobStorageDriver.MemoryBlobStorageDriver()
    });
    this.defaultBlobDriver = import_MemoryBlobStorageDriver.MemoryBlobStorageDriver.id;
  }
  /**
   * Get or create the in-memory store for a namespace.
   *
   * Only available when using the default (no custom opener) mode.  Useful for tests that need to pre-populate or
   * inspect storage directly.
   */
  store(namespace) {
    if (this.#opener !== void 0) {
      throw new import_MatterError.InternalError("store() is only available without a custom opener");
    }
    let store = this.#stores.get(namespace);
    if (!store) {
      store = import_MemoryStorageDriver.MemoryStorageDriver.create();
      this.#stores.set(namespace, store);
    }
    return store;
  }
  get isConfigured() {
    return true;
  }
  async open(namespace) {
    const name = typeof namespace === "string" ? namespace : namespace.namespace;
    let storage;
    if (this.#opener !== void 0) {
      storage = await this.#opener(name);
    } else {
      storage = this.store(name);
    }
    const manager = new import_StorageManager.StorageManager(storage);
    await manager.initialize();
    return manager;
  }
}
//# sourceMappingURL=MockStorageService.js.map
