import { __esDecorate, __runInitializers } from "tslib";
import { MessagePriority, ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core";
import { FunctionType, Message, MessageType, expectedResponse, messageTypes, priority, } from "@zwave-js/serial";
import { Bytes, num2hex } from "@zwave-js/shared";
let ExtNVMWriteLongBufferRequest = (() => {
    let _classDecorators = [messageTypes(MessageType.Request, FunctionType.ExtNVMWriteLongBuffer), priority(MessagePriority.Controller), expectedResponse(FunctionType.ExtNVMWriteLongBuffer)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var ExtNVMWriteLongBufferRequest = 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);
            ExtNVMWriteLongBufferRequest = _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.offset < 0 || options.offset > 0xffffff) {
                throw new ZWaveError("The offset must be a 24-bit number!", ZWaveErrorCodes.Argument_Invalid);
            }
            if (options.buffer.length < 1 || options.buffer.length > 0xffff) {
                throw new ZWaveError("The buffer must be between 1 and 65535 bytes long", ZWaveErrorCodes.Argument_Invalid);
            }
            this.offset = options.offset;
            this.buffer = options.buffer;
        }
        static from(_raw, _ctx) {
            throw new ZWaveError(`${this.name}: deserialization not implemented`, ZWaveErrorCodes.Deserialization_NotImplemented);
            // return new ExtNVMWriteLongBufferRequest({});
        }
        offset;
        buffer;
        serialize(ctx) {
            this.payload = new Bytes(5 + this.buffer.length);
            this.payload.writeUIntBE(this.offset, 0, 3);
            this.payload.writeUInt16BE(this.buffer.length, 3);
            this.payload.set(this.buffer, 5);
            return super.serialize(ctx);
        }
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: {
                    offset: num2hex(this.offset),
                    buffer: `(${this.buffer.length} byte${this.buffer.length === 1 ? "" : "s"})`,
                },
            };
        }
    };
    return ExtNVMWriteLongBufferRequest = _classThis;
})();
export { ExtNVMWriteLongBufferRequest };
let ExtNVMWriteLongBufferResponse = (() => {
    let _classDecorators = [messageTypes(MessageType.Response, FunctionType.ExtNVMWriteLongBuffer)];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = Message;
    var ExtNVMWriteLongBufferResponse = 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);
            ExtNVMWriteLongBufferResponse = _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.success = options.success;
        }
        static from(raw, _ctx) {
            const success = raw.payload[0] !== 0;
            return new this({
                success,
            });
        }
        success;
        isOK() {
            return this.success;
        }
        toLogEntry() {
            return {
                ...super.toLogEntry(),
                message: {
                    success: this.success,
                },
            };
        }
    };
    return ExtNVMWriteLongBufferResponse = _classThis;
})();
export { ExtNVMWriteLongBufferResponse };
//# sourceMappingURL=ExtNVMWriteLongBufferMessages.js.map