import * as Common from "../../core/common/common.js";
import { EmulationModel } from "./EmulationModel.js";
import { TargetManager } from "./TargetManager.js";
let throttlingManagerInstance;
export class CPUThrottlingManager extends Common.ObjectWrapper.ObjectWrapper {
  #cpuThrottlingRateInternal;
  constructor() {
    super();
    this.#cpuThrottlingRateInternal = CPUThrottlingRates.NoThrottling;
    TargetManager.instance().observeModels(EmulationModel, this);
  }
  static instance(opts = { forceNew: null }) {
    const { forceNew } = opts;
    if (!throttlingManagerInstance || forceNew) {
      throttlingManagerInstance = new CPUThrottlingManager();
    }
    return throttlingManagerInstance;
  }
  cpuThrottlingRate() {
    return this.#cpuThrottlingRateInternal;
  }
  setCPUThrottlingRate(rate) {
    this.#cpuThrottlingRateInternal = rate;
    for (const emulationModel of TargetManager.instance().models(EmulationModel)) {
      void emulationModel.setCPUThrottlingRate(this.#cpuThrottlingRateInternal);
    }
    this.dispatchEventToListeners(Events.RateChanged, this.#cpuThrottlingRateInternal);
  }
  modelAdded(emulationModel) {
    if (this.#cpuThrottlingRateInternal !== CPUThrottlingRates.NoThrottling) {
      void emulationModel.setCPUThrottlingRate(this.#cpuThrottlingRateInternal);
    }
  }
  modelRemoved(_emulationModel) {
  }
}
export var Events = /* @__PURE__ */ ((Events2) => {
  Events2["RateChanged"] = "RateChanged";
  return Events2;
})(Events || {});
export function throttlingManager() {
  return CPUThrottlingManager.instance();
}
export var CPUThrottlingRates = /* @__PURE__ */ ((CPUThrottlingRates2) => {
  CPUThrottlingRates2[CPUThrottlingRates2["NoThrottling"] = 1] = "NoThrottling";
  CPUThrottlingRates2[CPUThrottlingRates2["MidTierMobile"] = 4] = "MidTierMobile";
  CPUThrottlingRates2[CPUThrottlingRates2["LowEndMobile"] = 6] = "LowEndMobile";
  return CPUThrottlingRates2;
})(CPUThrottlingRates || {});
//# sourceMappingURL=CPUThrottlingManager.js.map
