"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 RvcRunModeServer_exports = {};
__export(RvcRunModeServer_exports, {
  RvcRunModeServer: () => RvcRunModeServer
});
module.exports = __toCommonJS(RvcRunModeServer_exports);
var import_mode_base = require("#behaviors/mode-base");
var import_mode_base2 = require("#clusters/mode-base");
var import_rvc_run_mode = require("#clusters/rvc-run-mode");
var import_general = require("#general");
var import_RvcRunModeBehavior = require("./RvcRunModeBehavior.js");
/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class RvcRunModeServer extends import_RvcRunModeBehavior.RvcRunModeBehavior {
  initialize() {
    this.#assertSupportedModes();
    import_mode_base.ModeUtils.assertMode(this.state.supportedModes, this.state.currentMode);
    this.reactTo(this.events.currentMode$Changing, this.#assertMode);
  }
  #assertSupportedModes() {
    import_mode_base.ModeUtils.assertSupportedModes(this.state.supportedModes);
    if (!this.state.supportedModes.some(
      ({ modeTags }) => modeTags.some(({ value }) => value === import_rvc_run_mode.RvcRunMode.ModeTag.Idle)
    )) {
      throw new import_general.ImplementationError("Provided supportedModes need to include at least one Idle mode tag");
    }
    if (!this.state.supportedModes.some(
      ({ modeTags }) => modeTags.some(({ value }) => value === import_rvc_run_mode.RvcRunMode.ModeTag.Cleaning)
    )) {
      throw new import_general.ImplementationError("Provided supportedModes need to include at least one Cleaning mode tag");
    }
    if (this.state.supportedModes.some(({ modeTags }) => {
      let exclusiveModeCounter = 0;
      exclusiveModeCounter += modeTags.some(({ value }) => value === import_rvc_run_mode.RvcRunMode.ModeTag.Idle) ? 1 : 0;
      exclusiveModeCounter += modeTags.some(({ value }) => value === import_rvc_run_mode.RvcRunMode.ModeTag.Cleaning) ? 1 : 0;
      exclusiveModeCounter += modeTags.some(({ value }) => value === import_rvc_run_mode.RvcRunMode.ModeTag.Mapping) ? 1 : 0;
      return exclusiveModeCounter > 1;
    })) {
      throw new import_general.ImplementationError(
        "Provided supportedModes must not have Idle, Cleaning and Mapping mode tags together in one mode"
      );
    }
  }
  #assertMode(newMode) {
    import_mode_base.ModeUtils.assertMode(this.state.supportedModes, newMode);
  }
  /**
   * This command is used to change device modes.
   * On receipt of this command the device shall respond with a ChangeToModeResponse command.
   *
   * The default implementation automatically validates the new mode against the supported modes and returns an error
   * if the new mode is not supported. If the new mode is supported, the current mode is updated to the new mode.
   *
   * If you need to override this with extra validation logic you can use
   * `ModeUtils.assertModeChange(this.state.supportedModes, this.state.currentMode, newMode)`
   * to just execute the validation and add your own validation requirements before or after these standard checks.
   * The above method returns a `ModeBase.ChangeToModeResponse` object that you can use to return the result of the
   * validation.
   */
  changeToMode({ newMode }) {
    const result = import_mode_base.ModeUtils.assertModeChange(this.state.supportedModes, this.state.currentMode, newMode);
    if (result.status === import_mode_base2.ModeBase.ModeChangeStatus.Success) {
      this.state.currentMode = newMode;
    }
    return result;
  }
}
//# sourceMappingURL=RvcRunModeServer.js.map
