import { __esDecorate, __runInitializers } from "tslib";
import { CommandClasses, TransmitOptions, validatePayload, } from "@zwave-js/core";
import { CCAPI } from "../lib/API.js";
import { CommandClass } from "../lib/CommandClass.js";
import { API, CCCommand, commandClass, implementedVersion, } from "../lib/CommandClassDecorators.js";
import { DeviceResetLocallyCommand } from "../lib/_Types.js";
// @noInterview: There is no interview procedure
let DeviceResetLocallyCCAPI = (() => {
    let _classDecorators = [API(CommandClasses["Device Reset Locally"])];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = CCAPI;
    var DeviceResetLocallyCCAPI = 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);
            DeviceResetLocallyCCAPI = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
            __runInitializers(_classThis, _classExtraInitializers);
        }
        supportsCommand(cmd) {
            switch (cmd) {
                case DeviceResetLocallyCommand.Notification:
                    return true; // This is mandatory
            }
            return super.supportsCommand(cmd);
        }
        async sendNotification() {
            this.assertSupportsCommand(DeviceResetLocallyCommand, DeviceResetLocallyCommand.Notification);
            const cc = new DeviceResetLocallyCCNotification({
                nodeId: this.endpoint.nodeId,
                endpointIndex: this.endpoint.index,
            });
            try {
                // This command is sent immediately before a hard reset of the controller.
                // If we don't wait for a callback (ack), the controller locks up when hard-resetting.
                await this.host.sendCommand(cc, {
                    ...this.commandOptions,
                    // Do not fall back to explorer frames
                    transmitOptions: TransmitOptions.ACK
                        | TransmitOptions.AutoRoute,
                    // Only try sending once
                    maxSendAttempts: 1,
                    // We don't want failures causing us to treat the node as asleep or dead
                    changeNodeStatusOnMissingACK: false,
                });
            }
            catch {
                // Don't care
            }
        }
    };
    return DeviceResetLocallyCCAPI = _classThis;
})();
export { DeviceResetLocallyCCAPI };
let DeviceResetLocallyCC = (() => {
    let _classDecorators = [commandClass(CommandClasses["Device Reset Locally"]), implementedVersion(1)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = CommandClass;
    var DeviceResetLocallyCC = 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);
            DeviceResetLocallyCC = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
            __runInitializers(_classThis, _classExtraInitializers);
        }
    };
    return DeviceResetLocallyCC = _classThis;
})();
export { DeviceResetLocallyCC };
let DeviceResetLocallyCCNotification = (() => {
    let _classDecorators = [CCCommand(DeviceResetLocallyCommand.Notification)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = DeviceResetLocallyCC;
    var DeviceResetLocallyCCNotification = 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);
            DeviceResetLocallyCCNotification = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
            __runInitializers(_classThis, _classExtraInitializers);
        }
        // @noLogEntry: This CC has no properties to log
        static from(raw, ctx) {
            // We need to make sure this doesn't get parsed accidentally, e.g. because of a bit flip
            // This CC has no payload
            validatePayload(raw.payload.length === 0);
            // The driver ensures before handling it that it is only received from the root device
            return new this({
                nodeId: ctx.sourceNodeId,
            });
        }
    };
    return DeviceResetLocallyCCNotification = _classThis;
})();
export { DeviceResetLocallyCCNotification };
//# sourceMappingURL=DeviceResetLocallyCC.js.map