/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { MutableCluster } from "../cluster/mutation/MutableCluster.js";
import { Attribute, Command, TlvNoResponse, OptionalAttribute, OptionalEvent } from "../cluster/Cluster.js";
import { TlvUInt32, TlvUInt64, TlvEnum, TlvUInt16, TlvInt8 } from "../tlv/TlvNumber.js";
import { TlvNullable } from "../tlv/TlvNullable.js";
import { TlvNoArguments } from "../tlv/TlvNoArguments.js";
import { BitFlag } from "../schema/BitmapSchema.js";
import { TlvByteString } from "../tlv/TlvString.js";
import { Priority } from "../globals/Priority.js";
import { TlvField, TlvObject } from "../tlv/TlvObject.js";
import { ClusterRegistry } from "../cluster/ClusterRegistry.js";
var WiFiNetworkDiagnostics;
((WiFiNetworkDiagnostics2) => {
  let Feature;
  ((Feature2) => {
    Feature2["PacketCounts"] = "PacketCounts";
    Feature2["ErrorCounts"] = "ErrorCounts";
  })(Feature = WiFiNetworkDiagnostics2.Feature || (WiFiNetworkDiagnostics2.Feature = {}));
  let SecurityType;
  ((SecurityType2) => {
    SecurityType2[SecurityType2["Unspecified"] = 0] = "Unspecified";
    SecurityType2[SecurityType2["None"] = 1] = "None";
    SecurityType2[SecurityType2["Wep"] = 2] = "Wep";
    SecurityType2[SecurityType2["Wpa"] = 3] = "Wpa";
    SecurityType2[SecurityType2["Wpa2"] = 4] = "Wpa2";
    SecurityType2[SecurityType2["Wpa3"] = 5] = "Wpa3";
  })(SecurityType = WiFiNetworkDiagnostics2.SecurityType || (WiFiNetworkDiagnostics2.SecurityType = {}));
  let WiFiVersion;
  ((WiFiVersion2) => {
    WiFiVersion2[WiFiVersion2["A"] = 0] = "A";
    WiFiVersion2[WiFiVersion2["B"] = 1] = "B";
    WiFiVersion2[WiFiVersion2["G"] = 2] = "G";
    WiFiVersion2[WiFiVersion2["N"] = 3] = "N";
    WiFiVersion2[WiFiVersion2["Ac"] = 4] = "Ac";
    WiFiVersion2[WiFiVersion2["Ax"] = 5] = "Ax";
    WiFiVersion2[WiFiVersion2["Ah"] = 6] = "Ah";
  })(WiFiVersion = WiFiNetworkDiagnostics2.WiFiVersion || (WiFiNetworkDiagnostics2.WiFiVersion = {}));
  WiFiNetworkDiagnostics2.TlvDisconnectionEvent = TlvObject({
    /**
     * This field shall contain the Reason Code field value for the Disassociation or Deauthentication event that
     * caused the disconnection and the value shall align with Table 9-49 "Reason codes" of IEEE 802.11-2020.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.15.8.1.1
     */
    reasonCode: TlvField(0, TlvUInt16)
  });
  let AssociationFailureCause;
  ((AssociationFailureCause2) => {
    AssociationFailureCause2[AssociationFailureCause2["Unknown"] = 0] = "Unknown";
    AssociationFailureCause2[AssociationFailureCause2["AssociationFailed"] = 1] = "AssociationFailed";
    AssociationFailureCause2[AssociationFailureCause2["AuthenticationFailed"] = 2] = "AuthenticationFailed";
    AssociationFailureCause2[AssociationFailureCause2["SsidNotFound"] = 3] = "SsidNotFound";
  })(AssociationFailureCause = WiFiNetworkDiagnostics2.AssociationFailureCause || (WiFiNetworkDiagnostics2.AssociationFailureCause = {}));
  WiFiNetworkDiagnostics2.TlvAssociationFailureEvent = TlvObject({
    /**
     * The Status field shall be set to a value from the AssociationFailureCauseEnum.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.15.8.2.1
     */
    associationFailureCause: TlvField(0, TlvEnum()),
    /**
     * The Status field shall be set to the Status Code value that was present in the last frame related to
     * association where Status Code was not equal to zero and which caused the failure of a last trial attempt, if
     * this last failure was due to one of the following Management frames:
     *
     *   • Association Response (Type 0, Subtype 1)
     *
     *   • Reassociation Response (Type 0, Subtype 3)
     *
     *   • Authentication (Type 0, Subtype 11)
     *
     * Table 9-50 "Status codes" of IEEE 802.11-2020 contains a description of all values possible.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.15.8.2.2
     */
    status: TlvField(1, TlvUInt16)
  });
  let ConnectionStatus;
  ((ConnectionStatus2) => {
    ConnectionStatus2[ConnectionStatus2["Connected"] = 0] = "Connected";
    ConnectionStatus2[ConnectionStatus2["NotConnected"] = 1] = "NotConnected";
  })(ConnectionStatus = WiFiNetworkDiagnostics2.ConnectionStatus || (WiFiNetworkDiagnostics2.ConnectionStatus = {}));
  WiFiNetworkDiagnostics2.TlvConnectionStatusEvent = TlvObject({ connectionStatus: TlvField(0, TlvEnum()) });
  WiFiNetworkDiagnostics2.ErrorCountsComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the count of the number of missed beacons the Node has detected. If the Node does not have an
       * ability to count beacons expected and not received, this value may remain set to zero.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.6
       */
      beaconLostCount: Attribute(5, TlvNullable(TlvUInt32), { omitChanges: true, default: 0 }),
      /**
       * Indicates the number of packets dropped either at ingress or egress, due to lack of buffer memory to
       * retain all packets on the network interface. The attribute shall be reset to 0 upon a reboot of the Node.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.13
       */
      overrunCount: Attribute(12, TlvNullable(TlvUInt64), { omitChanges: true, default: 0 })
    },
    commands: {
      /**
       * This command is used to reset the count attributes.
       *
       * Reception of this command shall reset the following attributes to 0:
       *
       *   • BeaconLostCount
       *
       *   • BeaconRxCount
       *
       *   • PacketMulticastRxCount
       *
       *   • PacketMulticastTxCount
       *
       *   • PacketUnicastRxCount
       *
       *   • PacketUnicastTxCount
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.7.1
       */
      resetCounts: Command(0, TlvNoArguments, 0, TlvNoResponse)
    }
  });
  WiFiNetworkDiagnostics2.PacketCountsComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the count of the number of received beacons. The total number of expected beacons that could
       * have been received during the interval since association SHOULD match the sum of BeaconRxCount and
       * BeaconLostCount. If the Node does not have an ability to report count of beacons received, this value may
       * remain set to zero.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.7
       */
      beaconRxCount: Attribute(6, TlvNullable(TlvUInt32), { omitChanges: true, default: 0 }),
      /**
       * Indicates the number of multicast packets received by the Node.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.8
       */
      packetMulticastRxCount: Attribute(7, TlvNullable(TlvUInt32), { omitChanges: true, default: 0 }),
      /**
       * Indicates the number of multicast packets transmitted by the Node.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.9
       */
      packetMulticastTxCount: Attribute(8, TlvNullable(TlvUInt32), { omitChanges: true, default: 0 }),
      /**
       * Indicates the number of unicast packets received by the Node.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.10
       */
      packetUnicastRxCount: Attribute(9, TlvNullable(TlvUInt32), { omitChanges: true, default: 0 }),
      /**
       * Indicates the number of unicast packets transmitted by the Node.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.11
       */
      packetUnicastTxCount: Attribute(10, TlvNullable(TlvUInt32), { omitChanges: true, default: 0 })
    }
  });
  WiFiNetworkDiagnostics2.Base = MutableCluster.Component({
    id: 54,
    name: "WiFiNetworkDiagnostics",
    revision: 1,
    features: {
      /**
       * Node makes available the counts for the number of received and transmitted packets on the Wi-Fi
       * interface.
       */
      packetCounts: BitFlag(0),
      /**
       * Node makes available the counts for the number of errors that have occurred during the reception and
       * transmission of packets on the Wi-Fi interface.
       */
      errorCounts: BitFlag(1)
    },
    attributes: {
      /**
       * Indicates the BSSID for which the Wi-Fi network the Node is currently connected.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.1
       */
      bssid: Attribute(0, TlvNullable(TlvByteString.bound({ length: 6 })), { default: null }),
      /**
       * Indicates the current type of Wi-Fi security used.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.2
       */
      securityType: Attribute(1, TlvNullable(TlvEnum()), { default: null }),
      /**
       * Indicates the current IEEE 802.11 standard version in use by the Node, per the table below.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.3
       */
      wiFiVersion: Attribute(2, TlvNullable(TlvEnum()), { default: null }),
      /**
       * Indicates the channel that Wi-Fi communication is currently operating on.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.4
       */
      channelNumber: Attribute(3, TlvNullable(TlvUInt16), { default: null }),
      /**
       * Indicates the current RSSI of the Node’s Wi-Fi radio in dBm.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.5
       */
      rssi: Attribute(
        4,
        TlvNullable(TlvInt8.bound({ min: -120, max: 0 })),
        { omitChanges: true, default: null }
      ),
      /**
       * Indicates the current maximum PHY rate of transfer of data in bits-per-second.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.6.12
       */
      currentMaxRate: OptionalAttribute(11, TlvNullable(TlvUInt64), { omitChanges: true, default: 0 })
    },
    events: {
      /**
       * The Disconnection Event shall indicate that a Node’s Wi-Fi connection has been disconnected as a result
       * of de-authenticated or dis-association and indicates the reason.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.8.1
       */
      disconnection: OptionalEvent(0, Priority.Info, WiFiNetworkDiagnostics2.TlvDisconnectionEvent),
      /**
       * The AssociationFailure event shall indicate that a Node has attempted to connect, or reconnect, to a
       * Wi-Fi access point, but is unable to successfully associate or authenticate, after exhausting all
       * internal retries of its supplicant.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.8.2
       */
      associationFailure: OptionalEvent(1, Priority.Info, WiFiNetworkDiagnostics2.TlvAssociationFailureEvent),
      /**
       * The ConnectionStatus Event shall indicate that a Node’s connection status to a Wi-Fi network has changed.
       * Connected, in this context, shall mean that a Node acting as a Wi-Fi station is successfully associated
       * to a Wi-Fi Access Point.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.15.8.3
       */
      connectionStatus: OptionalEvent(2, Priority.Info, WiFiNetworkDiagnostics2.TlvConnectionStatusEvent)
    },
    /**
     * This metadata controls which WiFiNetworkDiagnosticsCluster elements matter.js activates for specific feature
     * combinations.
     */
    extensions: MutableCluster.Extensions(
      { flags: { errorCounts: true }, component: WiFiNetworkDiagnostics2.ErrorCountsComponent },
      { flags: { packetCounts: true }, component: WiFiNetworkDiagnostics2.PacketCountsComponent }
    )
  });
  WiFiNetworkDiagnostics2.ClusterInstance = MutableCluster(WiFiNetworkDiagnostics2.Base);
  WiFiNetworkDiagnostics2.Cluster = WiFiNetworkDiagnostics2.ClusterInstance;
  const ERRCNT = { errorCounts: true };
  const PKTCNT = { packetCounts: true };
  WiFiNetworkDiagnostics2.CompleteInstance = MutableCluster({
    id: WiFiNetworkDiagnostics2.Cluster.id,
    name: WiFiNetworkDiagnostics2.Cluster.name,
    revision: WiFiNetworkDiagnostics2.Cluster.revision,
    features: WiFiNetworkDiagnostics2.Cluster.features,
    attributes: {
      ...WiFiNetworkDiagnostics2.Cluster.attributes,
      beaconLostCount: MutableCluster.AsConditional(
        WiFiNetworkDiagnostics2.ErrorCountsComponent.attributes.beaconLostCount,
        { mandatoryIf: [ERRCNT] }
      ),
      beaconRxCount: MutableCluster.AsConditional(
        WiFiNetworkDiagnostics2.PacketCountsComponent.attributes.beaconRxCount,
        { mandatoryIf: [PKTCNT] }
      ),
      packetMulticastRxCount: MutableCluster.AsConditional(
        WiFiNetworkDiagnostics2.PacketCountsComponent.attributes.packetMulticastRxCount,
        { mandatoryIf: [PKTCNT] }
      ),
      packetMulticastTxCount: MutableCluster.AsConditional(
        WiFiNetworkDiagnostics2.PacketCountsComponent.attributes.packetMulticastTxCount,
        { mandatoryIf: [PKTCNT] }
      ),
      packetUnicastRxCount: MutableCluster.AsConditional(
        WiFiNetworkDiagnostics2.PacketCountsComponent.attributes.packetUnicastRxCount,
        { mandatoryIf: [PKTCNT] }
      ),
      packetUnicastTxCount: MutableCluster.AsConditional(
        WiFiNetworkDiagnostics2.PacketCountsComponent.attributes.packetUnicastTxCount,
        { mandatoryIf: [PKTCNT] }
      ),
      overrunCount: MutableCluster.AsConditional(
        WiFiNetworkDiagnostics2.ErrorCountsComponent.attributes.overrunCount,
        { mandatoryIf: [ERRCNT] }
      )
    },
    commands: {
      resetCounts: MutableCluster.AsConditional(
        WiFiNetworkDiagnostics2.ErrorCountsComponent.commands.resetCounts,
        { mandatoryIf: [ERRCNT] }
      )
    },
    events: WiFiNetworkDiagnostics2.Cluster.events
  });
  WiFiNetworkDiagnostics2.Complete = WiFiNetworkDiagnostics2.CompleteInstance;
})(WiFiNetworkDiagnostics || (WiFiNetworkDiagnostics = {}));
const WiFiNetworkDiagnosticsCluster = WiFiNetworkDiagnostics.Cluster;
ClusterRegistry.register(WiFiNetworkDiagnostics.Complete);
export {
  WiFiNetworkDiagnostics,
  WiFiNetworkDiagnosticsCluster
};
//# sourceMappingURL=wi-fi-network-diagnostics.js.map
