"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 ServerInteraction_exports = {};
__export(ServerInteraction_exports, {
  ServerInteraction: () => ServerInteraction
});
module.exports = __toCommonJS(ServerInteraction_exports);
var import_Read = require("#action/request/Read.js");
var import_CommandInvokeResponse = require("#action/server/CommandInvokeResponse.js");
var import_EventReadResponse = require("#action/server/EventReadResponse.js");
var import_general = require("#general");
var import_AttributeReadResponse = require("./AttributeReadResponse.js");
var import_AttributeWriteResponse = require("./AttributeWriteResponse.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const logger = import_general.Logger.get("ServerInteraction");
class ServerInteraction {
  #node;
  constructor(node) {
    this.#node = node;
  }
  async *read(request, session) {
    let readInfo = "";
    if (import_Read.Read.containsAttribute(request)) {
      const attributeReader = new import_AttributeReadResponse.AttributeReadResponse(this.#node, session);
      yield* attributeReader.process(request);
      const { existent, status, success } = attributeReader.counts;
      readInfo = `${existent} matching attributes (${status ? `${status} status` : ""}${success ? `${success} values` : ""})`;
    }
    if (import_Read.Read.containsEvent(request)) {
      const eventReader = new import_EventReadResponse.EventReadResponse(this.#node, session);
      yield* eventReader.process(request);
      const { existent, status, success } = eventReader.counts;
      readInfo += `${readInfo.length > 0 ? ", " : ""}${existent} matching events (${status ? `${status} status, ` : ""}${success ? `${success} values` : ""})`;
    }
    logger.debug(`Read request resolved to ${readInfo}`);
  }
  subscribe(_request, _session) {
    throw new import_general.NotImplementedError();
  }
  async write(request, session) {
    const writer = new import_AttributeWriteResponse.AttributeWriteResponse(this.#node, session);
    return await writer.process(request);
  }
  async *invoke(request, session) {
    const invoker = new import_CommandInvokeResponse.CommandInvokeResponse(this.#node, session);
    yield* invoker.process(request);
  }
}
//# sourceMappingURL=ServerInteraction.js.map
