"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 DishwasherModeServer_exports = {};
__export(DishwasherModeServer_exports, {
  DishwasherModeServer: () => DishwasherModeServer
});
module.exports = __toCommonJS(DishwasherModeServer_exports);
var import_mode_base = require("#behaviors/mode-base");
var import_dishwasher_mode = require("@matter/types/clusters/dishwasher-mode");
var import_mode_base2 = require("@matter/types/clusters/mode-base");
var import_DishwasherModeBehavior = require("./DishwasherModeBehavior.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class DishwasherModeServer extends import_DishwasherModeBehavior.DishwasherModeBehavior {
  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_dishwasher_mode.DishwasherMode.ModeTag.Normal)
    )) {
      throw new Error("Provided supportedModes need to include at least Normal mode tag");
    }
  }
  #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=DishwasherModeServer.js.map
