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 EventMessage_1;
import { JsonNaming, PropertyNamingStrategy, JsonProperty, JsonSerialize, JsonDeserialize, JsonClassType, JsonParser } from "jackson-js";
import { MessagePayloadCompression } from "./constants";
import { Message, TRN, TRNSerializer } from "./message";
let ExtendedMessageLocation = class ExtendedMessageLocation {
    constructor(bucket, key) {
        this.Bucket = bucket;
        this.MetadataKey = key;
    }
};
__decorate([
    JsonProperty()
], ExtendedMessageLocation.prototype, "Bucket", void 0);
__decorate([
    JsonProperty()
], ExtendedMessageLocation.prototype, "MetadataKey", void 0);
ExtendedMessageLocation = __decorate([
    JsonNaming({ strategy: PropertyNamingStrategy.KEBAB_CASE })
], ExtendedMessageLocation);
export { ExtendedMessageLocation };
let MessagePayload = class MessagePayload {
    constructor(compression, body) {
        this.Body = body;
        this.Compression = compression;
    }
};
__decorate([
    JsonProperty()
], MessagePayload.prototype, "Body", void 0);
__decorate([
    JsonProperty()
], MessagePayload.prototype, "Compression", void 0);
MessagePayload = __decorate([
    JsonNaming({ strategy: PropertyNamingStrategy.KEBAB_CASE })
], MessagePayload);
export { MessagePayload };
let EventMessage = EventMessage_1 = class EventMessage extends Message {
    static construct(tmn, trn, ServiceTrn, config) {
        var _a;
        if (!((_a = config.Verb) === null || _a === void 0 ? void 0 : _a.length)) {
            throw ("event message without verb");
        }
        const evnt = new EventMessage_1(tmn, trn, ServiceTrn, config);
        return evnt;
    }
    constructor(tmn, trn, ServiceTrn, config = undefined) {
        super(tmn, ServiceTrn, config);
        this.Verb = (config === null || config === void 0 ? void 0 : config.Verb) || "";
        this.Trn = trn;
        this.Attributes = (config === null || config === void 0 ? void 0 : config.Attributes) || {};
        this.ExtendedLocation = (config === null || config === void 0 ? void 0 : config.ExtendedLocation) || undefined;
        if (config === null || config === void 0 ? void 0 : config.Payload) {
            this.setPayload(config === null || config === void 0 ? void 0 : config.Payload);
        }
        else {
            this.Payload = undefined;
        }
    }
    getVerb() {
        return this.Verb;
    }
    setPayload(payload) {
        switch (payload.Compression) {
            case MessagePayloadCompression.COMPRESSION_PLAIN: {
                this.Payload = payload;
                break;
            }
        }
    }
    getPayloadBody() {
        var _a;
        switch ((_a = this.Payload) === null || _a === void 0 ? void 0 : _a.Compression) {
            case MessagePayloadCompression.COMPRESSION_PLAIN: {
                return this.Payload.Body;
            }
        }
    }
    hasPayload() {
        return this.Payload != undefined;
    }
    GetPayload(creatorClass, isArray = false) {
        const parser = new JsonParser();
        return parser.parse(JSON.stringify(this.getPayloadBody()), {
            mainCreator: () => isArray ? [Array, [creatorClass]] : [creatorClass],
            features: {
                deserialization: {
                    FAIL_ON_UNKNOWN_PROPERTIES: false
                }
            }
        });
    }
    addAttribute(key, value) {
        this.Attributes[key] = value;
    }
    isExtended() {
        return this.ExtendedLocation != undefined;
    }
    getExtendedMessageMetadataBucket() {
        var _a;
        return (_a = this.ExtendedLocation) === null || _a === void 0 ? void 0 : _a.Bucket;
    }
    getExtendedMessageMetadataReference() {
        var _a;
        return (_a = this.ExtendedLocation) === null || _a === void 0 ? void 0 : _a.MetadataKey;
    }
};
__decorate([
    JsonProperty(),
    JsonSerialize({ using: TRNSerializer.serialize }),
    JsonDeserialize({ using: TRNSerializer.deserialize }),
    JsonClassType({ type: () => [TRN] })
], EventMessage.prototype, "Trn", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [Object] })
], EventMessage.prototype, "Attributes", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [ExtendedMessageLocation] })
], EventMessage.prototype, "ExtendedLocation", void 0);
__decorate([
    JsonProperty(),
    JsonClassType({ type: () => [MessagePayload] })
], EventMessage.prototype, "Payload", void 0);
__decorate([
    JsonProperty()
], EventMessage.prototype, "Verb", void 0);
EventMessage = EventMessage_1 = __decorate([
    JsonNaming({ strategy: PropertyNamingStrategy.KEBAB_CASE })
], EventMessage);
export { EventMessage };
//# sourceMappingURL=event-message.js.map