import { __esDecorate, __runInitializers } from "tslib";
import { MessagePriority, encodeNodeID, parseNodeID, } from "@zwave-js/core";
import { FunctionType, Message, MessageType, expectedCallback, expectedResponse, messageTypes, priority, } from "@zwave-js/serial";
import { Bytes } from "@zwave-js/shared";
import { ApplicationUpdateRequestNodeInfoReceived, ApplicationUpdateRequestNodeInfoRequestFailed, } from "../application/ApplicationUpdateRequest.js";
let RequestNodeInfoResponse = (() => {
    let _classDecorators = [messageTypes(MessageType.Response, FunctionType.RequestNodeInfo)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var RequestNodeInfoResponse = 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);
            RequestNodeInfoResponse = _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.wasSent = options.wasSent;
        }
        static from(raw, _ctx) {
            const wasSent = raw.payload[0] !== 0;
            return new this({
                wasSent,
            });
        }
        wasSent;
        isOK() {
            return this.wasSent;
        }
        serialize(ctx) {
            this.payload = Bytes.from([this.wasSent ? 0x01 : 0]);
            return super.serialize(ctx);
        }
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: { "was sent": this.wasSent },
            };
        }
    };
    return RequestNodeInfoResponse = _classThis;
})();
export { RequestNodeInfoResponse };
function testCallbackForRequestNodeInfoRequest(sent, received) {
    return ((received instanceof ApplicationUpdateRequestNodeInfoReceived
        && received.nodeId === sent.nodeId)
        || received instanceof ApplicationUpdateRequestNodeInfoRequestFailed);
}
let RequestNodeInfoRequest = (() => {
    let _classDecorators = [messageTypes(MessageType.Request, FunctionType.RequestNodeInfo), expectedResponse(RequestNodeInfoResponse), expectedCallback(testCallbackForRequestNodeInfoRequest), priority(MessagePriority.NodeQuery)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var RequestNodeInfoRequest = 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);
            RequestNodeInfoRequest = _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.nodeId = options.nodeId;
        }
        static from(raw, ctx) {
            const nodeId = parseNodeID(raw.payload, ctx.nodeIdType, 0).nodeId;
            return new this({
                nodeId,
            });
        }
        nodeId;
        needsCallbackId() {
            // Not sure why it is this way, but this message contains no callback id
            return false;
        }
        serialize(ctx) {
            this.payload = encodeNodeID(this.nodeId, ctx.nodeIdType);
            return super.serialize(ctx);
        }
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: { "node id": this.nodeId },
            };
        }
    };
    return RequestNodeInfoRequest = _classThis;
})();
export { RequestNodeInfoRequest };
//# sourceMappingURL=RequestNodeInfoMessages.js.map