import { __esDecorate, __runInitializers } from "tslib";
import { MessagePriority, NUM_LR_NODEMASK_SEGMENT_BYTES, NUM_LR_NODES_PER_SEGMENT, encodeLongRangeNodeBitMask, parseLongRangeNodeBitMask, } from "@zwave-js/core";
import { FunctionType, Message, MessageType, expectedResponse, messageTypes, priority, } from "@zwave-js/serial";
import { Bytes } from "@zwave-js/shared";
function getFirstNodeId(segmentNumber) {
    return 256 + NUM_LR_NODES_PER_SEGMENT * segmentNumber;
}
let GetLongRangeNodesRequest = (() => {
    let _classDecorators = [messageTypes(MessageType.Request, FunctionType.GetLongRangeNodes), expectedResponse(FunctionType.GetLongRangeNodes), priority(MessagePriority.Controller)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var GetLongRangeNodesRequest = class extends _classSuper {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            GetLongRangeNodesRequest = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
            __runInitializers(_classThis, _classExtraInitializers);
        }
        constructor(options) {
            super(options);
            this.segmentNumber = options.segmentNumber;
        }
        static from(raw, _ctx) {
            const segmentNumber = raw.payload[0];
            return new this({
                segmentNumber,
            });
        }
        segmentNumber;
        serialize(ctx) {
            this.payload = Bytes.from([this.segmentNumber]);
            return super.serialize(ctx);
        }
    };
    return GetLongRangeNodesRequest = _classThis;
})();
export { GetLongRangeNodesRequest };
let GetLongRangeNodesResponse = (() => {
    let _classDecorators = [messageTypes(MessageType.Response, FunctionType.GetLongRangeNodes)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var GetLongRangeNodesResponse = class extends _classSuper {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            GetLongRangeNodesResponse = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
            __runInitializers(_classThis, _classExtraInitializers);
        }
        constructor(options) {
            super(options);
            this.moreNodes = options.moreNodes;
            this.segmentNumber = options.segmentNumber;
            this.nodeIds = options.nodeIds;
        }
        static from(raw, _ctx) {
            const moreNodes = raw.payload[0] != 0;
            const segmentNumber = raw.payload[1];
            const listLength = raw.payload[2];
            const listStart = 3;
            const listEnd = listStart + listLength;
            let nodeIds;
            if (listEnd <= raw.payload.length) {
                const nodeBitMask = raw.payload.subarray(listStart, listEnd);
                nodeIds = parseLongRangeNodeBitMask(nodeBitMask, getFirstNodeId(segmentNumber));
            }
            else {
                nodeIds = [];
            }
            return new this({
                moreNodes,
                segmentNumber,
                nodeIds,
            });
        }
        moreNodes;
        segmentNumber;
        nodeIds;
        serialize(ctx) {
            this.payload = new Bytes(3 + NUM_LR_NODEMASK_SEGMENT_BYTES);
            this.payload[0] = this.moreNodes ? 1 : 0;
            this.payload[1] = this.segmentNumber;
            this.payload[2] = NUM_LR_NODEMASK_SEGMENT_BYTES;
            const nodeBitMask = encodeLongRangeNodeBitMask(this.nodeIds, getFirstNodeId(this.segmentNumber));
            this.payload.set(nodeBitMask, 3);
            return super.serialize(ctx);
        }
    };
    return GetLongRangeNodesResponse = _classThis;
})();
export { GetLongRangeNodesResponse };
//# sourceMappingURL=GetLongRangeNodesMessages.js.map