import { __esDecorate, __runInitializers } from "tslib";
import { MessagePriority, TransmitStatus, ZWaveError, ZWaveErrorCodes, encodeNodeID, } 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 AssignReturnRouteRequestBase = (() => {
    let _classDecorators = [messageTypes(MessageType.Request, FunctionType.AssignReturnRoute), priority(MessagePriority.Normal)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var AssignReturnRouteRequestBase = 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);
            AssignReturnRouteRequestBase = _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 AssignReturnRouteRequest.from(raw, ctx);
            }
            else {
                return AssignReturnRouteRequestTransmitReport.from(raw, ctx);
            }
        }
    };
    return AssignReturnRouteRequestBase = _classThis;
})();
export { AssignReturnRouteRequestBase };
let AssignReturnRouteRequest = (() => {
    let _classDecorators = [expectedResponse(FunctionType.AssignReturnRoute), expectedCallback(FunctionType.AssignReturnRoute)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = AssignReturnRouteRequestBase;
    var AssignReturnRouteRequest = 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);
            AssignReturnRouteRequest = _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);
            if (options.nodeId === options.destinationNodeId) {
                throw new ZWaveError(`The source and destination node must not be identical`, ZWaveErrorCodes.Argument_Invalid);
            }
            this.nodeId = options.nodeId;
            this.destinationNodeId = options.destinationNodeId;
        }
        static from(_raw, _ctx) {
            throw new ZWaveError(`${this.name}: deserialization not implemented`, ZWaveErrorCodes.Deserialization_NotImplemented);
            // return new AssignReturnRouteRequest({});
        }
        nodeId;
        destinationNodeId;
        serialize(ctx) {
            this.assertCallbackId();
            const nodeId = encodeNodeID(this.nodeId, ctx.nodeIdType);
            const destinationNodeId = encodeNodeID(this.destinationNodeId, ctx.nodeIdType);
            this.payload = Bytes.concat([
                nodeId,
                destinationNodeId,
                [this.callbackId],
            ]);
            return super.serialize(ctx);
        }
    };
    return AssignReturnRouteRequest = _classThis;
})();
export { AssignReturnRouteRequest };
let AssignReturnRouteResponse = (() => {
    let _classDecorators = [messageTypes(MessageType.Response, FunctionType.AssignReturnRoute)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var AssignReturnRouteResponse = 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);
            AssignReturnRouteResponse = _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.hasStarted = options.hasStarted;
        }
        static from(raw, _ctx) {
            const hasStarted = raw.payload[0] !== 0;
            return new this({
                hasStarted,
            });
        }
        isOK() {
            return this.hasStarted;
        }
        hasStarted;
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: { "has started": this.hasStarted },
            };
        }
    };
    return AssignReturnRouteResponse = _classThis;
})();
export { AssignReturnRouteResponse };
export class AssignReturnRouteRequestTransmitReport extends AssignReturnRouteRequestBase {
    constructor(options) {
        super(options);
        // TODO: Check implementation:
        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,
        });
    }
    isOK() {
        // The other statuses are technically "not OK", but they are caused by
        // not being able to contact the node. We don't want the node to be marked
        // as dead because of that
        return this.transmitStatus !== TransmitStatus.NoAck;
    }
    transmitStatus;
    toLogEntry() {
        return {
            ...super.toLogEntry(),
            message: {
                "callback id": this.callbackId ?? "(not set)",
                "transmit status": getEnumMemberName(TransmitStatus, this.transmitStatus),
            },
        };
    }
}
//# sourceMappingURL=AssignReturnRouteMessages.js.map