"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 ClientEndpointStore_exports = {};
__export(ClientEndpointStore_exports, {
  ClientEndpointStore: () => ClientEndpointStore
});
module.exports = __toCommonJS(ClientEndpointStore_exports);
var import_EndpointStore = require("#storage/EndpointStore.js");
var import_DatasourceStore = require("#storage/server/DatasourceStore.js");
var import_protocol = require("@matter/protocol");
var import_DatasourceCache = require("./DatasourceCache.js");
var import_RemoteWriteParticipant = require("./RemoteWriteParticipant.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class ClientEndpointStore extends import_EndpointStore.EndpointStore {
  #owner;
  #number;
  constructor(owner, number, storage) {
    super(storage);
    this.#owner = owner;
    this.#number = number;
    if (!this.#number) {
      const commissioning = this.initialValues.get("commissioning");
      if (commissioning?.peerAddress) {
        commissioning.peerAddress = (0, import_protocol.PeerAddress)(commissioning.peerAddress);
      }
    }
  }
  get number() {
    return this.#number;
  }
  /**
   * Shortcut to persisted peer address so we can use in logging prior to full initialization.
   */
  get peerAddress() {
    return this.initialValues.get("commissioning")?.["peerAddress"];
  }
  participantFor(transaction) {
    let participant = transaction.getParticipant(this.#owner);
    if (participant === void 0) {
      participant = new import_RemoteWriteParticipant.RemoteWriteParticipant(this.#owner);
      transaction.addParticipants(participant);
    }
    return participant;
  }
  /**
   * Create a {@link Datasource.ExternallyMutableStore} for a behavior.
   */
  createStoreForBehavior(behaviorId) {
    const initialValues = this.consumeInitialValues(behaviorId);
    return (0, import_DatasourceCache.DatasourceCache)(this, behaviorId, initialValues);
  }
  /**
   * Create a {@link Datasource.Store} for a behavior that does not track a remote cluster.
   */
  createStoreForLocalBehavior(behaviorId) {
    const initialValues = this.consumeInitialValues(behaviorId);
    return (0, import_DatasourceStore.DatasourceStore)(this, behaviorId, initialValues);
  }
}
//# sourceMappingURL=ClientEndpointStore.js.map
