"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 SUCUpdateEntriesFile_exports = {};
__export(SUCUpdateEntriesFile_exports, {
  SUCUpdateEntriesFileIDV0: () => SUCUpdateEntriesFileIDV0,
  SUCUpdateEntriesFileV0: () => SUCUpdateEntriesFileV0,
  SUCUpdateEntriesFileV5: () => SUCUpdateEntriesFileV5,
  SUCUpdateEntriesFileV5IDBase: () => SUCUpdateEntriesFileV5IDBase,
  SUCUpdateEntriesFileV5IDMax: () => SUCUpdateEntriesFileV5IDMax,
  SUC_UPDATES_PER_FILE_V5: () => SUC_UPDATES_PER_FILE_V5,
  sucUpdateIndexToSUCUpdateEntriesFileIDV5: () => sucUpdateIndexToSUCUpdateEntriesFileIDV5
});
module.exports = __toCommonJS(SUCUpdateEntriesFile_exports);
var import_tslib = require("tslib");
var import_shared = require("@zwave-js/shared");
var import_consts = require("../../../consts.js");
var import_sucUpdateEntry = require("../../common/sucUpdateEntry.js");
var import_NVMFile = require("./NVMFile.js");
const SUC_UPDATES_PER_FILE_V5 = 8;
const SUCUpdateEntriesFileIDV0 = 327683;
let SUCUpdateEntriesFileV0 = (() => {
  let _classDecorators = [(0, import_NVMFile.nvmFileID)(SUCUpdateEntriesFileIDV0), (0, import_NVMFile.nvmSection)("protocol")];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = import_NVMFile.NVMFile;
  var SUCUpdateEntriesFileV02 = class extends _classSuper {
    static {
      __name(this, "SUCUpdateEntriesFileV0");
    }
    static {
      _classThis = this;
    }
    static {
      const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
      (0, import_tslib.__esDecorate)(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
      SUCUpdateEntriesFileV02 = _classThis = _classDescriptor.value;
      if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
      (0, import_tslib.__runInitializers)(_classThis, _classExtraInitializers);
    }
    constructor(options) {
      super(options);
      if ((0, import_NVMFile.gotDeserializationOptions)(options)) {
        this.updateEntries = [];
        for (let entry = 0; entry < import_consts.SUC_MAX_UPDATES; entry++) {
          const offset = entry * import_consts.SUC_UPDATE_ENTRY_SIZE;
          const updateEntry = (0, import_sucUpdateEntry.parseSUCUpdateEntry)(this.payload, offset);
          if (updateEntry)
            this.updateEntries.push(updateEntry);
        }
      } else {
        this.updateEntries = options.updateEntries;
      }
    }
    updateEntries;
    serialize() {
      this.payload = new import_shared.Bytes(import_consts.SUC_MAX_UPDATES * import_consts.SUC_UPDATE_ENTRY_SIZE).fill(0);
      for (let i = 0; i < this.updateEntries.length; i++) {
        const offset = i * import_consts.SUC_UPDATE_ENTRY_SIZE;
        const entry = this.updateEntries[i];
        this.payload.set((0, import_sucUpdateEntry.encodeSUCUpdateEntry)(entry), offset);
      }
      return super.serialize();
    }
    // oxlint-disable-next-line typescript/explicit-module-boundary-types
    toJSON() {
      return {
        ...super.toJSON(),
        "SUC update entries": this.updateEntries
      };
    }
  };
  return SUCUpdateEntriesFileV02 = _classThis;
})();
const SUCUpdateEntriesFileV5IDBase = 344064;
const SUCUpdateEntriesFileV5IDMax = SUCUpdateEntriesFileV5IDBase + import_consts.SUC_MAX_UPDATES / SUC_UPDATES_PER_FILE_V5 - 1;
function sucUpdateIndexToSUCUpdateEntriesFileIDV5(index) {
  return SUCUpdateEntriesFileV5IDBase + Math.floor(index / SUC_UPDATES_PER_FILE_V5);
}
__name(sucUpdateIndexToSUCUpdateEntriesFileIDV5, "sucUpdateIndexToSUCUpdateEntriesFileIDV5");
let SUCUpdateEntriesFileV5 = (() => {
  let _classDecorators = [(0, import_NVMFile.nvmFileID)((id) => id >= SUCUpdateEntriesFileV5IDBase && id <= SUCUpdateEntriesFileV5IDMax), (0, import_NVMFile.nvmSection)("protocol")];
  let _classDescriptor;
  let _classExtraInitializers = [];
  let _classThis;
  let _classSuper = import_NVMFile.NVMFile;
  var SUCUpdateEntriesFileV52 = class extends _classSuper {
    static {
      __name(this, "SUCUpdateEntriesFileV5");
    }
    static {
      _classThis = this;
    }
    static {
      const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
      (0, import_tslib.__esDecorate)(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
      SUCUpdateEntriesFileV52 = _classThis = _classDescriptor.value;
      if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
      (0, import_tslib.__runInitializers)(_classThis, _classExtraInitializers);
    }
    constructor(options) {
      super(options);
      if ((0, import_NVMFile.gotDeserializationOptions)(options)) {
        this.updateEntries = [];
        for (let entry = 0; entry < SUC_UPDATES_PER_FILE_V5; entry++) {
          const offset = entry * import_consts.SUC_UPDATE_ENTRY_SIZE;
          const updateEntry = (0, import_sucUpdateEntry.parseSUCUpdateEntry)(this.payload, offset);
          if (updateEntry)
            this.updateEntries.push(updateEntry);
        }
      } else {
        this.updateEntries = options.updateEntries;
      }
    }
    updateEntries;
    serialize() {
      this.payload = new import_shared.Bytes(SUC_UPDATES_PER_FILE_V5 * import_consts.SUC_UPDATE_ENTRY_SIZE).fill(255);
      for (let i = 0; i < this.updateEntries.length; i++) {
        const offset = i * import_consts.SUC_UPDATE_ENTRY_SIZE;
        const entry = this.updateEntries[i];
        this.payload.set((0, import_sucUpdateEntry.encodeSUCUpdateEntry)(entry), offset);
      }
      return super.serialize();
    }
    // oxlint-disable-next-line typescript/explicit-module-boundary-types
    toJSON() {
      return {
        ...super.toJSON(),
        "SUC update entries": this.updateEntries
      };
    }
  };
  return SUCUpdateEntriesFileV52 = _classThis;
})();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SUCUpdateEntriesFileIDV0,
  SUCUpdateEntriesFileV0,
  SUCUpdateEntriesFileV5,
  SUCUpdateEntriesFileV5IDBase,
  SUCUpdateEntriesFileV5IDMax,
  SUC_UPDATES_PER_FILE_V5,
  sucUpdateIndexToSUCUpdateEntriesFileIDV5
});
//# sourceMappingURL=SUCUpdateEntriesFile.js.map
