"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 ota_software_update_requestor_exports = {};
__export(ota_software_update_requestor_exports, {
  OtaSoftwareUpdateRequestor: () => OtaSoftwareUpdateRequestor,
  OtaSoftwareUpdateRequestorCluster: () => OtaSoftwareUpdateRequestorCluster
});
module.exports = __toCommonJS(ota_software_update_requestor_exports);
var import_MutableCluster = require("../cluster/mutation/MutableCluster.js");
var import_Cluster = require("../cluster/Cluster.js");
var import_TlvArray = require("../tlv/TlvArray.js");
var import_TlvObject = require("../tlv/TlvObject.js");
var import_NodeId = require("../datatype/NodeId.js");
var import_EndpointNumber = require("../datatype/EndpointNumber.js");
var import_FabricIndex = require("../datatype/FabricIndex.js");
var import_model = require("#model");
var import_TlvBoolean = require("../tlv/TlvBoolean.js");
var import_TlvNumber = require("../tlv/TlvNumber.js");
var import_TlvNullable = require("../tlv/TlvNullable.js");
var import_VendorId = require("../datatype/VendorId.js");
var import_TlvString = require("../tlv/TlvString.js");
var import_ClusterRegistry = require("../cluster/ClusterRegistry.js");
/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
var OtaSoftwareUpdateRequestor;
((OtaSoftwareUpdateRequestor2) => {
  OtaSoftwareUpdateRequestor2.TlvProviderLocation = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall contain the Node ID of the OTA Provider to contact within the Fabric identified by the
     * FabricIndex.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.4.4.1
     */
    providerNodeId: (0, import_TlvObject.TlvField)(1, import_NodeId.TlvNodeId),
    /**
     * This field shall contain the endpoint number which has the OTA Provider device type and OTA
     *
     * Software Update Provider cluster server on the ProviderNodeID. This is provided to avoid having to do
     * discovery of the location of that endpoint by walking over all endpoints and checking their Descriptor
     * Cluster.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.4.4.2
     */
    endpoint: (0, import_TlvObject.TlvField)(2, import_EndpointNumber.TlvEndpointNumber),
    fabricIndex: (0, import_TlvObject.TlvField)(254, import_FabricIndex.TlvFabricIndex)
  });
  let UpdateState;
  ((UpdateState2) => {
    UpdateState2[UpdateState2["Unknown"] = 0] = "Unknown";
    UpdateState2[UpdateState2["Idle"] = 1] = "Idle";
    UpdateState2[UpdateState2["Querying"] = 2] = "Querying";
    UpdateState2[UpdateState2["DelayedOnQuery"] = 3] = "DelayedOnQuery";
    UpdateState2[UpdateState2["Downloading"] = 4] = "Downloading";
    UpdateState2[UpdateState2["Applying"] = 5] = "Applying";
    UpdateState2[UpdateState2["DelayedOnApply"] = 6] = "DelayedOnApply";
    UpdateState2[UpdateState2["RollingBack"] = 7] = "RollingBack";
    UpdateState2[UpdateState2["DelayedOnUserConsent"] = 8] = "DelayedOnUserConsent";
  })(UpdateState = OtaSoftwareUpdateRequestor2.UpdateState || (OtaSoftwareUpdateRequestor2.UpdateState = {}));
  let AnnouncementReason;
  ((AnnouncementReason2) => {
    AnnouncementReason2[AnnouncementReason2["SimpleAnnouncement"] = 0] = "SimpleAnnouncement";
    AnnouncementReason2[AnnouncementReason2["UpdateAvailable"] = 1] = "UpdateAvailable";
    AnnouncementReason2[AnnouncementReason2["UrgentUpdateAvailable"] = 2] = "UrgentUpdateAvailable";
  })(AnnouncementReason = OtaSoftwareUpdateRequestor2.AnnouncementReason || (OtaSoftwareUpdateRequestor2.AnnouncementReason = {}));
  OtaSoftwareUpdateRequestor2.TlvAnnounceOtaProviderRequest = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall contain the Node ID of a Node implementing the OTA Provider cluster server, on the
     * accessing fabric.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.6.1.1
     */
    providerNodeId: (0, import_TlvObject.TlvField)(0, import_NodeId.TlvNodeId),
    /**
     * This field shall contain the assigned Vendor ID of the Node invoking this command, as it would appear in
     * that Node’s Basic Information Cluster VendorID attribute.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.6.1.2
     */
    vendorId: (0, import_TlvObject.TlvField)(1, import_VendorId.TlvVendorId),
    /**
     * This field shall contain a value expressing the reason for the announcement.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.6.1.3
     */
    announcementReason: (0, import_TlvObject.TlvField)(2, (0, import_TlvNumber.TlvEnum)()),
    /**
     * This optional field, if present, shall consist of a top-level anonymous list; each list element shall have a
     * profile-specific tag encoded in fully-qualified form. Each list element shall contain a
     * manufacturer-specific payload, which the Node invoking this command wants to expose to the receiving Node.
     * This payload may be used for any purpose and SHOULD be as small as practical, especially if invoked to
     * groups, in order to reduce networking burden of these payloads.
     *
     * This field SHOULD only be included if the sending OTA Provider has knowledge that some recipient can make
     * use of it.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.6.1.4
     */
    metadataForNode: (0, import_TlvObject.TlvOptionalField)(3, import_TlvString.TlvByteString.bound({ maxLength: 512 })),
    /**
     * This field shall contain the endpoint number which has the OTA Provider device type and OTA Software Update
     * Provider cluster server on the ProviderNodeID. This is provided to avoid having to do discovery of the
     * location of that endpoint by walking over all endpoints and checking their Descriptor Cluster.
     *
     * When Generated
     *
     * An OTA Provider may invoke this command directly to an OTA Requestor, to announce its presence as an OTA
     * Provider on the Fabric.
     *
     * These announcements, if made, SHOULD be made at most once every 24 hours for any given target Node, to
     * assist OTA Requestors in discovering available OTA Provider resources, unless the AnnouncementReason is
     * UrgentUpdateAvailable, in which case this command may be more frequent.
     *
     * Any invocation shall be made with a delay of at least 1 second between invocations from a given OTA
     * Provider, to reduce burden on the networking infrastructure and affect a form of serialized jitter. It is
     * recommended to offset the first announcement of a round (i.e. new set of announcements after a previous
     * complete set) by a random delay time with a distribution span of >= 60 seconds to jitter announcement
     * schedules over time.
     *
     * Effect on Receipt
     *
     * On receipt of this command, an OTA Requestor SHOULD consider the new ProviderNodeID and AnnouncementReason
     * to possibly query for new software sooner than it would have with its default behavior.
     *
     * The OTA Requestor SHOULD NOT update entries in the DefaultOTAProviders list based on announcements.
     *
     * The receiving Node may ignore the content of the announcement if it is unable or unwilling to further query
     * OTA Providers temporarily, or if its provider list is full. If the announcement is ignored, the response
     * SHOULD be SUCCESS.
     *
     * Depending on the value of the AnnouncementReason field, the OTA Requestor may have to query the OTA
     * Provider. See Section 11.20.7.6.1.3, “AnnouncementReason Field” for the different values and their meaning.
     *
     * If present, the MetadataForNode field’s may be used by a receiving OTA Requestor in any way it deems
     * satisfactory. The MetadataForNode field SHOULD be empty under most normal operational circumstance, but can
     * be useful in environments such as field trials or integration test environments to hint at additional
     * capabilities which OTA Requestors may use in a particular Vendor-specific context.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.6.1.5
     */
    endpoint: (0, import_TlvObject.TlvField)(4, import_EndpointNumber.TlvEndpointNumber),
    fabricIndex: (0, import_TlvObject.TlvField)(254, import_FabricIndex.TlvFabricIndex)
  });
  let ChangeReason;
  ((ChangeReason2) => {
    ChangeReason2[ChangeReason2["Unknown"] = 0] = "Unknown";
    ChangeReason2[ChangeReason2["Success"] = 1] = "Success";
    ChangeReason2[ChangeReason2["Failure"] = 2] = "Failure";
    ChangeReason2[ChangeReason2["TimeOut"] = 3] = "TimeOut";
    ChangeReason2[ChangeReason2["DelayByProvider"] = 4] = "DelayByProvider";
  })(ChangeReason = OtaSoftwareUpdateRequestor2.ChangeReason || (OtaSoftwareUpdateRequestor2.ChangeReason = {}));
  OtaSoftwareUpdateRequestor2.TlvStateTransitionEvent = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall be set to the state that preceded the transition causing this event to be generated, if
     * such a state existed. If no previous state exists, the value shall be Unknown.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.1.1
     */
    previousState: (0, import_TlvObject.TlvField)(0, (0, import_TlvNumber.TlvEnum)()),
    /**
     * This field shall be set to the state now in effect through the transition causing this event to be generated.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.1.2
     */
    newState: (0, import_TlvObject.TlvField)(1, (0, import_TlvNumber.TlvEnum)()),
    /**
     * This field shall be set to the reason why this event was generated.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.1.3
     */
    reason: (0, import_TlvObject.TlvField)(2, (0, import_TlvNumber.TlvEnum)()),
    /**
     * This field shall be set to the target SoftwareVersion which is the subject of the operation, whenever the
     * NewState is Downloading, Applying or RollingBack. Otherwise TargetSoftwareVersion shall be null.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.1.4
     */
    targetSoftwareVersion: (0, import_TlvObject.TlvField)(3, (0, import_TlvNullable.TlvNullable)(import_TlvNumber.TlvUInt32))
  });
  OtaSoftwareUpdateRequestor2.TlvVersionAppliedEvent = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall be set to the same value as the one available in the Software Version attribute of the
     * Basic Information Cluster for the newly executing version.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.2.1
     */
    softwareVersion: (0, import_TlvObject.TlvField)(0, import_TlvNumber.TlvUInt32),
    /**
     * This field shall be set to the ProductID applying to the executing version, as reflected by the Basic
     * Information Cluster. This can be used to detect a product updating its definition due to a large-scale
     * functional update that may impact aspects of the product reflected in the DeviceModel schema of the
     * Distributed Compliance Ledger.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.2.2
     */
    productId: (0, import_TlvObject.TlvField)(1, import_TlvNumber.TlvUInt16)
  });
  OtaSoftwareUpdateRequestor2.TlvDownloadErrorEvent = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall be set to the value of the SoftwareVersion being downloaded, matching the SoftwareVersion
     * field of the QueryImageResponse that caused the failing download to take place.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.3.1
     */
    softwareVersion: (0, import_TlvObject.TlvField)(0, import_TlvNumber.TlvUInt32),
    /**
     * This field shall be set to the number of bytes that have been downloaded during the failing transfer that
     * caused this event to be generated.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.3.2
     */
    bytesDownloaded: (0, import_TlvObject.TlvField)(1, import_TlvNumber.TlvUInt64),
    /**
     * This field shall be set to the nearest integer percent value reflecting how far within the transfer the
     * failure occurred during the failing transfer that caused this event to be generated, unless the total length
     * of the transfer is unknown, in which case it shall be null.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.3.3
     */
    progressPercent: (0, import_TlvObject.TlvField)(2, (0, import_TlvNullable.TlvNullable)(import_TlvNumber.TlvUInt8.bound({ max: 100 }))),
    /**
     * This field SHOULD be set to some internal product-specific error code, closest in temporal/functional
     * proximity to the failure that caused this event to be generated. Otherwise, it shall be null. This event
     * field may be used for debugging purposes and no uniform definition exists related to its meaning.
     *
     * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.3.4
     */
    platformCode: (0, import_TlvObject.TlvField)(3, (0, import_TlvNullable.TlvNullable)(import_TlvNumber.TlvInt64))
  });
  OtaSoftwareUpdateRequestor2.ClusterInstance = (0, import_MutableCluster.MutableCluster)({
    id: 42,
    name: "OtaSoftwareUpdateRequestor",
    revision: 1,
    attributes: {
      /**
       * This field is a list of ProviderLocation whose entries shall be set by Administrators, either during
       * Commissioning or at a later time, to set the ProviderLocation for the default OTA Provider Node to use
       * for software updates on a given Fabric.
       *
       * There shall NOT be more than one entry per Fabric. On a list update that would introduce more than one
       * entry per fabric, the write shall fail with CONSTRAINT_ERROR status code.
       *
       * Provider Locations obtained using the AnnounceOTAProvider command shall NOT overwrite values set in the
       * DefaultOTAProviders attribute.
       *
       * @see {@link MatterSpecification.v13.Core} § 11.20.7.5.1
       */
      defaultOtaProviders: (0, import_Cluster.WritableFabricScopedAttribute)(
        0,
        (0, import_TlvArray.TlvArray)(OtaSoftwareUpdateRequestor2.TlvProviderLocation),
        { default: [], writeAcl: import_model.AccessLevel.Administer }
      ),
      /**
       * This field shall be set to True if the OTA Requestor is currently able to be updated. Otherwise, it
       * shall be set to False in case of any condition preventing update being possible, such as insufficient
       * capacity of an internal battery. This field is merely informational for diagnostics purposes and shall
       * NOT affect the responses provided by an OTA Provider to an OTA Requestor.
       *
       * @see {@link MatterSpecification.v13.Core} § 11.20.7.5.2
       */
      updatePossible: (0, import_Cluster.Attribute)(1, import_TlvBoolean.TlvBoolean, { default: true }),
      /**
       * This field shall reflect the current state of the OTA Requestor with regards to obtaining software
       * updates. See Section 11.20.7.4.2, “UpdateStateEnum Type” for possible values.
       *
       * This field SHOULD be updated in a timely manner whenever OTA Requestor internal state updates.
       *
       * @see {@link MatterSpecification.v13.Core} § 11.20.7.5.3
       */
      updateState: (0, import_Cluster.Attribute)(2, (0, import_TlvNumber.TlvEnum)(), { default: 0 /* Unknown */ }),
      /**
       * This field shall reflect the percentage value of progress, relative to the current UpdateState, if
       * applicable to the state.
       *
       * The value of this field shall be null if a progress indication does not apply to the current state.
       *
       * A value of 0 shall indicate that the beginning has occurred. A value of 100 shall indicate completion.
       *
       * This field may be updated infrequently. Some care SHOULD be taken by Nodes to avoid over- reporting
       * progress when this attribute is part of a subscription.
       *
       * @see {@link MatterSpecification.v13.Core} § 11.20.7.5.4
       */
      updateStateProgress: (0, import_Cluster.Attribute)(3, (0, import_TlvNullable.TlvNullable)(import_TlvNumber.TlvUInt8.bound({ max: 100 })), { default: null })
    },
    commands: {
      /**
       * This command may be invoked by Administrators to announce the presence of a particular OTA Provider.
       *
       * This command shall be scoped to the accessing fabric.
       *
       * If the accessing fabric index is 0, this command shall fail with an UNSUPPORTED_ACCESS status code.
       *
       * @see {@link MatterSpecification.v13.Core} § 11.20.7.6.1
       */
      announceOtaProvider: (0, import_Cluster.OptionalCommand)(
        0,
        OtaSoftwareUpdateRequestor2.TlvAnnounceOtaProviderRequest,
        0,
        import_Cluster.TlvNoResponse,
        { invokeAcl: import_model.AccessLevel.Administer }
      )
    },
    events: {
      /**
       * This event shall be generated when a change of the UpdateState attribute occurs due to an OTA Requestor
       * moving through the states necessary to query for updates.
       *
       * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.1
       */
      stateTransition: (0, import_Cluster.Event)(0, import_Cluster.EventPriority.Info, OtaSoftwareUpdateRequestor2.TlvStateTransitionEvent),
      /**
       * This event shall be generated whenever a new version starts executing after being applied due to a
       * software update. This event SHOULD be generated even if a software update was done using means outside
       * of this cluster.
       *
       * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.2
       */
      versionApplied: (0, import_Cluster.Event)(1, import_Cluster.EventPriority.Critical, OtaSoftwareUpdateRequestor2.TlvVersionAppliedEvent),
      /**
       * This event shall be generated whenever an error occurs during OTA Requestor download operation.
       *
       * @see {@link MatterSpecification.v13.Core} § 11.20.7.7.3
       */
      downloadError: (0, import_Cluster.Event)(2, import_Cluster.EventPriority.Info, OtaSoftwareUpdateRequestor2.TlvDownloadErrorEvent)
    }
  });
  OtaSoftwareUpdateRequestor2.Cluster = OtaSoftwareUpdateRequestor2.ClusterInstance;
  OtaSoftwareUpdateRequestor2.Complete = OtaSoftwareUpdateRequestor2.Cluster;
})(OtaSoftwareUpdateRequestor || (OtaSoftwareUpdateRequestor = {}));
const OtaSoftwareUpdateRequestorCluster = OtaSoftwareUpdateRequestor.Cluster;
import_ClusterRegistry.ClusterRegistry.register(OtaSoftwareUpdateRequestor.Complete);
//# sourceMappingURL=ota-software-update-requestor.js.map
