"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var CommandMessage_1, CommandMessageCallback_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandMessageCallback = exports.CommandMessageArguments = exports.CommandMessage = void 0;
const jackson_js_1 = require("jackson-js");
const constants_1 = require("./constants");
const event_message_1 = require("./event-message");
const message_1 = require("./message");
let CommandMessage = CommandMessage_1 = class CommandMessage extends message_1.Message {
    constructor(tmn, ServiceTrn, config = undefined) {
        super(tmn, ServiceTrn, config);
        this.getCallbackMessages = (servicetrn, result) => {
            var _a;
            if (!this.Callbacks || 0 == this.Callbacks.length) {
                return [];
            }
            const callbacks = new Array();
            for (const c of this.Callbacks) {
                if (c.Tmn.getType() == constants_1.MessageType.MESSAGE_TYPE_COMMAND) {
                    callbacks.push(new CommandMessage_1(c.Tmn, servicetrn, {
                        ParentID: this.MessageID,
                        GroupId: this.GroupId,
                        Callbacks: c.Callbacks,
                        Arguments: Object.assign(Object.assign({}, c.Arguments), { Forwarded: result })
                    }));
                }
                else {
                    if (!((_a = c.Verb) === null || _a === void 0 ? void 0 : _a.length)) {
                        throw ("callback event message without verb");
                    }
                    callbacks.push(event_message_1.EventMessage.construct(c.Tmn, c.Trn, servicetrn, {
                        ParentID: this.MessageID,
                        GroupId: this.GroupId,
                        Verb: c.Verb,
                        Attributes: c.Attributes,
                        ExtendedLocation: c.ExtendedLocation,
                        Payload: c.Payload,
                    }));
                }
            }
            return callbacks;
        };
        this.Callbacks = (config === null || config === void 0 ? void 0 : config.Callbacks) || new Array();
        this.Arguments = (config === null || config === void 0 ? void 0 : config.Arguments) || {};
    }
};
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [CommandMessageArguments] })
], CommandMessage.prototype, "Arguments", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [CommandMessageCallback]] })
], CommandMessage.prototype, "Callbacks", void 0);
CommandMessage = CommandMessage_1 = __decorate([
    (0, jackson_js_1.JsonInclude)({ value: jackson_js_1.JsonIncludeType.NON_NULL }),
    (0, jackson_js_1.JsonNaming)({ strategy: jackson_js_1.PropertyNamingStrategy.KEBAB_CASE })
], CommandMessage);
exports.CommandMessage = CommandMessage;
let CommandMessageArguments = class CommandMessageArguments {
    constructor(config = undefined) {
        this.Forwarded = config === null || config === void 0 ? void 0 : config.Forwarded;
        this.Presets = config === null || config === void 0 ? void 0 : config.Presets;
    }
};
__decorate([
    (0, jackson_js_1.JsonProperty)()
], CommandMessageArguments.prototype, "Presets", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], CommandMessageArguments.prototype, "Forwarded", void 0);
CommandMessageArguments = __decorate([
    (0, jackson_js_1.JsonNaming)({ strategy: jackson_js_1.PropertyNamingStrategy.KEBAB_CASE }),
    (0, jackson_js_1.JsonInclude)({ value: jackson_js_1.JsonIncludeType.NON_NULL })
], CommandMessageArguments);
exports.CommandMessageArguments = CommandMessageArguments;
let CommandMessageCallback = CommandMessageCallback_1 = class CommandMessageCallback {
    constructor(tmn, config = undefined) {
        this.Tmn = tmn;
        this.Verb = (config === null || config === void 0 ? void 0 : config.Verb) || undefined;
        this.Trn = (config === null || config === void 0 ? void 0 : config.Trn) || undefined;
        this.Attributes = (config === null || config === void 0 ? void 0 : config.Attributes) || {};
        this.Arguments = config === null || config === void 0 ? void 0 : config.Arguments;
        this.Callbacks = ((config === null || config === void 0 ? void 0 : config.Callbacks) || new Array());
        this.ExtendedLocation = (config === null || config === void 0 ? void 0 : config.ExtendedLocation) || undefined;
        this.Payload = (config === null || config === void 0 ? void 0 : config.Payload) || undefined;
    }
    addAttribute(key, value) {
        this.Attributes[key] = value;
    }
    addCallback(callback) {
        this.Callbacks.push(callback);
    }
    setArguments(args) {
        this.Arguments = args;
    }
};
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [message_1.TMN] }),
    (0, jackson_js_1.JsonSerialize)({ using: message_1.TMNSerializer.serialize }),
    (0, jackson_js_1.JsonDeserialize)({ using: message_1.TMNSerializer.deserialize })
], CommandMessageCallback.prototype, "Tmn", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonSerialize)({ using: message_1.TRNSerializer.serialize }),
    (0, jackson_js_1.JsonDeserialize)({ using: message_1.TRNSerializer.deserialize }),
    (0, jackson_js_1.JsonClassType)({ type: () => [message_1.TRN] })
], CommandMessageCallback.prototype, "Trn", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Object] })
], CommandMessageCallback.prototype, "Attributes", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [CommandMessageArguments] })
], CommandMessageCallback.prototype, "Arguments", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [Array, [CommandMessageCallback_1]] })
], CommandMessageCallback.prototype, "Callbacks", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [event_message_1.ExtendedMessageLocation] })
], CommandMessageCallback.prototype, "ExtendedLocation", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)(),
    (0, jackson_js_1.JsonClassType)({ type: () => [event_message_1.MessagePayload] })
], CommandMessageCallback.prototype, "Payload", void 0);
__decorate([
    (0, jackson_js_1.JsonProperty)()
], CommandMessageCallback.prototype, "Verb", void 0);
CommandMessageCallback = CommandMessageCallback_1 = __decorate([
    (0, jackson_js_1.JsonInclude)({ value: jackson_js_1.JsonIncludeType.NON_NULL }),
    (0, jackson_js_1.JsonNaming)({ strategy: jackson_js_1.PropertyNamingStrategy.KEBAB_CASE })
], CommandMessageCallback);
exports.CommandMessageCallback = CommandMessageCallback;
//# sourceMappingURL=command-message.js.map