/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { DescriptorServer } from "#behaviors/descriptor";
import { PowerSource } from "#clusters/power-source";
import { Seconds } from "#general";
import { ClusterType } from "#types";
import { PowerSourceBehavior } from "./PowerSourceBehavior.js";
const PowerSourceLevelBase = PowerSourceBehavior.with(PowerSource.Feature.Battery, PowerSource.Feature.Rechargeable);
class PowerSourceBaseServer extends PowerSourceLevelBase {
  async initialize() {
    (await this.agent.load(DescriptorServer)).addDeviceTypes("PowerSource");
    [
      this.events.batPercentRemaining$Changed,
      this.events.batTimeRemaining$Changed,
      this.events.batTimeToFullCharge$Changed
    ].forEach((event) => {
      if (event !== void 0) {
        event.quiet.minimumEmitInterval = Seconds(10);
      }
    });
    if (this.state.status === void 0) {
      this.state.status = PowerSource.PowerSourceStatus.Unspecified;
    }
    if (this.state.description === void 0) {
      if (this.features.wired) {
        this.state.description = "Mains power";
      } else if (this.features.battery) {
        this.state.description = "Battery power";
      }
    }
    if (this.features.battery) {
      if (this.state.batChargeLevel === void 0) {
        this.state.batChargeLevel = PowerSource.BatChargeLevel.Ok;
      }
      if (this.state.batReplaceability === void 0) {
        this.state.batReplaceability = PowerSource.BatReplaceability.Unspecified;
      }
    }
    if (this.features.wired) {
      const state = this.state;
      if (state.wiredCurrentType === void 0) {
        state.wiredCurrentType = PowerSource.WiredCurrentType.Ac;
      }
    }
  }
}
class PowerSourceServer extends PowerSourceBaseServer.for(ClusterType(PowerSource.Base)) {
}
export {
  PowerSourceBaseServer,
  PowerSourceServer
};
//# sourceMappingURL=PowerSourceServer.js.map
