/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ImplementationError, Millis } from "#general";
import { DatatypeModel, FieldElement } from "#model";
import { MAXIMUM_COMMISSIONING_TIMEOUT } from "#types";
import { Advertiser } from "../Advertiser.js";
import { CommissioningMode } from "../CommissioningMode.js";
import { BleAdvertisement } from "./BleAdvertisement.js";
class BleAdvertiser extends Advertiser {
  #peripheral;
  #config;
  #isClosed = false;
  constructor(peripheral, options) {
    super(options?.lifetime);
    this.#peripheral = peripheral;
    this.#config = BleAdvertiser.Configuration(options);
  }
  get peripheral() {
    return this.#peripheral;
  }
  get config() {
    return this.#config;
  }
  getAdvertisement(description) {
    this.#assertOpen();
    if (description.kind !== "commissionable" || description.mode !== CommissioningMode.Basic) {
      return;
    }
    return new BleAdvertisement(this, description);
  }
  #assertOpen() {
    if (this.#isClosed) {
      throw new ImplementationError("Illegal operation on closed BleBroadcaster");
    }
  }
}
((BleAdvertiser2) => {
  function Configuration(options) {
    return {
      timeout: MAXIMUM_COMMISSIONING_TIMEOUT,
      earlyInterval: Millis(20),
      lateInterval: Millis(150),
      extendedInterval: Millis(1285),
      ...options
    };
  }
  BleAdvertiser2.Configuration = Configuration;
  BleAdvertiser2.OptionsSchema = new DatatypeModel(
    { name: "BleAdvertiserOptions", type: "struct" },
    FieldElement({ name: "add", type: "octstr" }),
    FieldElement({ name: "timeout", type: "uint32" }),
    FieldElement({ name: "earlyInterval", type: "uint32" }),
    FieldElement({ name: "lateInterval", type: "uint32" }),
    FieldElement({ name: "extendedInterval", type: "uint32" })
  );
})(BleAdvertiser || (BleAdvertiser = {}));
export {
  BleAdvertiser
};
//# sourceMappingURL=BleAdvertiser.js.map
