/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Read } from "#action/request/Read.js";
import { CommandInvokeResponse } from "#action/server/CommandInvokeResponse.js";
import { EventReadResponse } from "#action/server/EventReadResponse.js";
import { Logger, NotImplementedError } from "@matter/general";
import { AttributeReadResponse } from "./AttributeReadResponse.js";
import { AttributeWriteResponse } from "./AttributeWriteResponse.js";
const logger = Logger.get("ServerInteraction");
class ServerInteraction {
  #node;
  constructor(node) {
    this.#node = node;
  }
  async *read(request, session) {
    let readInfo = "";
    if (Read.containsAttribute(request)) {
      const attributeReader = new 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 (Read.containsEvent(request)) {
      const eventReader = new 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 NotImplementedError();
  }
  async write(request, session) {
    const writer = new AttributeWriteResponse(this.#node, session);
    return await writer.process(request);
  }
  async *invoke(request, session) {
    const invoker = new CommandInvokeResponse(this.#node, session);
    yield* invoker.process(request);
  }
}
export {
  ServerInteraction
};
//# sourceMappingURL=ServerInteraction.js.map
