"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 OnlineServerInteraction_exports = {};
__export(OnlineServerInteraction_exports, {
  OnlineServerInteraction: () => OnlineServerInteraction
});
module.exports = __toCommonJS(OnlineServerInteraction_exports);
var import_RemoteActorContext = require("#behavior/context/server/RemoteActorContext.js");
var import_general = require("@matter/general");
var import_protocol = require("@matter/protocol");
class OnlineServerInteraction {
  #interaction;
  constructor(node) {
    this.#interaction = new import_protocol.ServerInteraction(node);
  }
  async *read(request, context) {
    const session = (0, import_RemoteActorContext.RemoteActorContext)(context).beginReadOnly();
    try {
      for await (const report of this.#interaction.read(request, session)) {
        yield report;
      }
    } finally {
      session[Symbol.dispose]();
    }
  }
  subscribe(_request, _context) {
    throw new import_general.NotImplementedError("subscribe not implemented");
  }
  /**
   * Process write requests and return results.
   * The caller is responsible for messaging/chunking and list state tracking.
   */
  async write(request, context) {
    return (0, import_RemoteActorContext.RemoteActorContext)(context).act((session) => this.#interaction.write(request, session));
  }
  /**
   * Process invoke requests and yield results.
   * The caller is responsible for messaging/chunking.
   */
  async *invoke(request, context) {
    const session = (0, import_RemoteActorContext.RemoteActorContext)({ ...context, command: true }).open();
    try {
      for await (const chunk of this.#interaction.invoke(request, session)) {
        yield chunk;
      }
    } catch (error) {
      await session.reject(error);
    }
    await session.resolve(void 0);
  }
}
//# sourceMappingURL=OnlineServerInteraction.js.map
