import { __esDecorate, __runInitializers } from "tslib";
import { MessagePriority, encodeCCList, getCCName, } from "@zwave-js/core";
import { FunctionType, Message, MessageType, messageTypes, priority, } from "@zwave-js/serial";
import { Bytes, num2hex } from "@zwave-js/shared";
let SetApplicationNodeInformationRequest = (() => {
    let _classDecorators = [messageTypes(MessageType.Request, FunctionType.SetApplicationNodeInformation), priority(MessagePriority.Controller)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var SetApplicationNodeInformationRequest = 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);
            SetApplicationNodeInformationRequest = _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.isListening = options.isListening;
            this.genericDeviceClass = options.genericDeviceClass;
            this.specificDeviceClass = options.specificDeviceClass;
            this.supportedCCs = options.supportedCCs;
            this.controlledCCs = options.controlledCCs;
        }
        isListening;
        genericDeviceClass;
        specificDeviceClass;
        supportedCCs;
        controlledCCs;
        serialize(ctx) {
            const ccList = encodeCCList(this.supportedCCs, this.controlledCCs);
            const ccListLength = Math.min(ccList.length, 35);
            this.payload = Bytes.from([
                this.isListening ? 0x01 : 0, // APPLICATION_NODEINFO_LISTENING
                this.genericDeviceClass,
                this.specificDeviceClass,
                ccListLength,
                ...ccList.subarray(0, ccListLength),
            ]);
            return super.serialize(ctx);
        }
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: {
                    "is listening": this.isListening,
                    "generic device class": num2hex(this.genericDeviceClass),
                    "specific device class": num2hex(this.specificDeviceClass),
                    "supported CCs": this.supportedCCs
                        .map((cc) => `\n· ${getCCName(cc)}`)
                        .join(""),
                    "controlled CCs": this.controlledCCs
                        .map((cc) => `\n· ${getCCName(cc)}`)
                        .join(""),
                },
            };
        }
    };
    return SetApplicationNodeInformationRequest = _classThis;
})();
export { SetApplicationNodeInformationRequest };
//# sourceMappingURL=SetApplicationNodeInformationRequest.js.map