import { __esDecorate, __runInitializers } from "tslib";
import { Powerlevel } from "@zwave-js/cc";
import { MessagePriority, TransmitStatus, encodeNodeID, parseNodeID, } from "@zwave-js/core";
import { FunctionType, Message, MessageOrigin, MessageType, expectedCallback, expectedResponse, messageTypes, priority, } from "@zwave-js/serial";
import { Bytes, getEnumMemberName } from "@zwave-js/shared";
let SendTestFrameRequestBase = (() => {
    let _classDecorators = [messageTypes(MessageType.Request, FunctionType.SendTestFrame), priority(MessagePriority.Normal)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var SendTestFrameRequestBase = 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);
            SendTestFrameRequestBase = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
            __runInitializers(_classThis, _classExtraInitializers);
        }
        static from(raw, ctx) {
            if (ctx.origin === MessageOrigin.Host) {
                return SendTestFrameRequest.from(raw, ctx);
            }
            else {
                return SendTestFrameTransmitReport.from(raw, ctx);
            }
        }
    };
    return SendTestFrameRequestBase = _classThis;
})();
export { SendTestFrameRequestBase };
let SendTestFrameRequest = (() => {
    let _classDecorators = [expectedResponse(FunctionType.SendTestFrame), expectedCallback(FunctionType.SendTestFrame)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = SendTestFrameRequestBase;
    var SendTestFrameRequest = 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);
            SendTestFrameRequest = _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.testNodeId = options.testNodeId;
            this.powerlevel = options.powerlevel;
        }
        static from(raw, ctx) {
            let offset = 0;
            const { nodeId: testNodeId, bytesRead: nodeIdBytes } = parseNodeID(raw.payload, ctx.nodeIdType, offset);
            offset += nodeIdBytes;
            const powerlevel = raw.payload[offset++];
            const callbackId = raw.payload[offset++];
            return new this({
                testNodeId,
                powerlevel,
                callbackId,
            });
        }
        testNodeId;
        powerlevel;
        serialize(ctx) {
            this.assertCallbackId();
            const nodeId = encodeNodeID(this.testNodeId, ctx.nodeIdType);
            this.payload = Bytes.concat([
                nodeId,
                [
                    this.powerlevel,
                    this.callbackId,
                ],
            ]);
            return super.serialize(ctx);
        }
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: {
                    "test node id": this.testNodeId,
                    powerlevel: getEnumMemberName(Powerlevel, this.powerlevel),
                    "callback id": this.callbackId ?? "(not set)",
                },
            };
        }
    };
    return SendTestFrameRequest = _classThis;
})();
export { SendTestFrameRequest };
let SendTestFrameResponse = (() => {
    let _classDecorators = [messageTypes(MessageType.Response, FunctionType.SendTestFrame)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var SendTestFrameResponse = 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);
            SendTestFrameResponse = _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;
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: { "was sent": this.wasSent },
            };
        }
    };
    return SendTestFrameResponse = _classThis;
})();
export { SendTestFrameResponse };
export class SendTestFrameTransmitReport extends SendTestFrameRequestBase {
    constructor(options) {
        super(options);
        this.callbackId = options.callbackId;
        this.transmitStatus = options.transmitStatus;
    }
    static from(raw, _ctx) {
        const callbackId = raw.payload[0];
        const transmitStatus = raw.payload[1];
        return new this({
            callbackId,
            transmitStatus,
        });
    }
    transmitStatus;
    isOK() {
        return this.transmitStatus === TransmitStatus.OK;
    }
    toLogEntry() {
        return {
            ...super.toLogEntry(),
            message: {
                "callback id": this.callbackId ?? "(not set)",
                "transmit status": getEnumMemberName(TransmitStatus, this.transmitStatus),
            },
        };
    }
}
//# sourceMappingURL=SendTestFrameMessages.js.map