"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 UnsecuredSession_exports = {};
__export(UnsecuredSession_exports, {
  UNICAST_UNSECURE_SESSION_ID: () => UNICAST_UNSECURE_SESSION_ID,
  UnsecuredSession: () => UnsecuredSession
});
module.exports = __toCommonJS(UnsecuredSession_exports);
var import_Mark = require("#common/Mark.js");
var import_errors = require("#protocol/errors.js");
var import_general = require("@matter/general");
var import_types = require("@matter/types");
var import_MessageCodec = require("../codec/MessageCodec.js");
var import_MessageReceptionState = require("../protocol/MessageReceptionState.js");
var import_Session = require("./Session.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const UNICAST_UNSECURE_SESSION_ID = 0;
class UnsecuredSession extends import_Session.Session {
  #initiatorNodeId;
  closingAfterExchangeFinished = false;
  supportsMRP = true;
  type = import_MessageCodec.SessionType.Unicast;
  constructor(config) {
    const { crypto, initiatorNodeId, isInitiator } = config;
    super({
      ...config,
      setActiveTimestamp: !isInitiator,
      // When we are the initiator we assume the node is in idle mode
      messageReceptionState: new import_MessageReceptionState.MessageReceptionStateUnencryptedWithRollover()
    });
    this.#initiatorNodeId = initiatorNodeId ?? import_types.NodeId.randomOperationalNodeId(crypto);
  }
  get isSecure() {
    return false;
  }
  get isPase() {
    return false;
  }
  decode(packet) {
    return import_MessageCodec.MessageCodec.decodePayload(packet);
  }
  encode(message) {
    return import_MessageCodec.MessageCodec.encodePayload(message);
  }
  get attestationChallengeKey() {
    throw new import_general.MatterFlowError("Not supported on an unsecure session");
  }
  setFabric(_fabric) {
    throw new import_general.MatterFlowError("Not supported on an unsecure session");
  }
  get via() {
    return import_general.Diagnostic.via(`${import_Mark.Mark.SESSION}unsecured#${this.#initiatorNodeId.toString(16)}`);
  }
  get id() {
    return UNICAST_UNSECURE_SESSION_ID;
  }
  get peerSessionId() {
    return UNICAST_UNSECURE_SESSION_ID;
  }
  get nodeId() {
    return this.#initiatorNodeId;
  }
  get peerNodeId() {
    return void 0;
  }
  get associatedFabric() {
    throw new import_errors.NoAssociatedFabricError("Session needs to be a secure session");
  }
  detachChannel() {
    this.manager?.unsecuredSessions.delete(this.nodeId);
    return super.detachChannel();
  }
  async close() {
    this.manager?.unsecuredSessions.delete(this.nodeId);
    await super.close();
  }
}
//# sourceMappingURL=UnsecuredSession.js.map
