import { __esDecorate, __runInitializers } from "tslib";
import { MAX_REPEATERS, MessagePriority, RouteKind, ZWaveDataRate, ZWaveError, ZWaveErrorCodes, encodeNodeID, parseNodeID, } from "@zwave-js/core";
import { FunctionType, Message, MessageType, expectedResponse, messageTypes, priority, } from "@zwave-js/serial";
import { getEnumMemberName } from "@zwave-js/shared";
let GetPriorityRouteRequest = (() => {
    let _classDecorators = [messageTypes(MessageType.Request, FunctionType.GetPriorityRoute), priority(MessagePriority.Normal), expectedResponse(FunctionType.GetPriorityRoute)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var GetPriorityRouteRequest = 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);
            GetPriorityRouteRequest = _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.destinationNodeId = options.destinationNodeId;
        }
        static from(_raw, _ctx) {
            throw new ZWaveError(`${this.name}: deserialization not implemented`, ZWaveErrorCodes.Deserialization_NotImplemented);
            // return new GetPriorityRouteRequest({});
        }
        destinationNodeId;
        serialize(ctx) {
            this.payload = encodeNodeID(this.destinationNodeId, ctx.nodeIdType);
            return super.serialize(ctx);
        }
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: {
                    "node ID": this.destinationNodeId,
                },
            };
        }
    };
    return GetPriorityRouteRequest = _classThis;
})();
export { GetPriorityRouteRequest };
let GetPriorityRouteResponse = (() => {
    let _classDecorators = [messageTypes(MessageType.Response, FunctionType.GetPriorityRoute)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var GetPriorityRouteResponse = 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);
            GetPriorityRouteResponse = _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);
            // TODO: Check implementation:
            this.destinationNodeId = options.destinationNodeId;
            this.routeKind = options.routeKind;
            this.repeaters = options.repeaters;
            this.routeSpeed = options.routeSpeed;
        }
        static from(raw, ctx) {
            let offset = 0;
            const { nodeId, bytesRead: nodeIdBytes } = parseNodeID(raw.payload, ctx.nodeIdType, offset);
            offset += nodeIdBytes;
            const destinationNodeId = nodeId;
            const routeKind = raw.payload[offset++];
            let repeaters;
            let routeSpeed;
            if (routeKind) {
                repeaters = [
                    ...raw.payload.subarray(offset, offset + MAX_REPEATERS),
                ].filter((id) => id > 0);
                routeSpeed = raw.payload[offset + MAX_REPEATERS];
            }
            return new this({
                destinationNodeId,
                routeKind,
                repeaters,
                routeSpeed,
            });
        }
        destinationNodeId;
        routeKind;
        repeaters;
        routeSpeed;
        toLogEntry() {
            let message = {
                "node ID": this.destinationNodeId,
            };
            if (this.routeKind !== RouteKind.None) {
                message = {
                    ...message,
                    "route kind": getEnumMemberName(RouteKind, this.routeKind),
                    repeaters: this.repeaters?.length
                        ? this.repeaters.join(" -> ")
                        : "none",
                    "route speed": getEnumMemberName(ZWaveDataRate, this.routeSpeed),
                };
            }
            else {
                message = {
                    ...message,
                    route: "(not set)",
                };
            }
            return {
                ...super.toLogEntry(),
                message,
            };
        }
    };
    return GetPriorityRouteResponse = _classThis;
})();
export { GetPriorityRouteResponse };
//# sourceMappingURL=GetPriorityRouteMessages.js.map