"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 __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var Tag_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tag = exports.TagSerializer = void 0;
const jackson_js_1 = require("jackson-js");
const lodash_1 = __importDefault(require("lodash"));
class TagSerializer {
    static serialize(t) {
        return t.tag;
    }
    static deserialize(o) {
        return new Tag(o);
    }
}
exports.TagSerializer = TagSerializer;
let Tag = Tag_1 = class Tag {
    constructor(tag) {
        // ES6 functions count as properties, therefore we need to exclude them
        this.unitaryPrefix = () => {
            return this.tag.split(":").splice(0, 5).join(":");
        };
        this.discriminator = () => {
            const t = this.tag.split(":");
            return t[t.length - 1];
        };
        this.concat = (...tokens) => {
            if (!this.valid()) {
                throw Error("trying to concat on an invalid tag");
            }
            lodash_1.default.forEach(tokens, s => {
                this.tag = this.tag + `:${s}`;
            });
            return this;
        };
        this.finalize = (finType) => {
            if (!this.valid()) {
                throw Error("trying to finalize on an invalid tag");
            }
            return new Tag_1(this.tag + `:${finType}`);
        };
        this.valid = () => {
            return this.tag.split(":").length >= 2;
        };
        this.pop = () => {
            const token = this.tag.split(":");
            token.pop();
            this.tag = token.join(":");
            return this;
        };
        this.getCategory = () => {
            return this.tag.split(":")[0];
        };
        this.getNamespace = () => {
            return this.tag.split(":")[1];
        };
        this.getAdditionalTokens = () => {
            const tokens = this.tag.split(":");
            if (tokens.length <= 2) {
                return [];
            }
            return tokens.splice(2, tokens.length);
        };
        this.tag = tag;
    }
    static newTag(category, namespace) {
        return new Tag_1(`${category}:${namespace}`);
    }
    toString() {
        return this.tag;
    }
};
__decorate([
    (0, jackson_js_1.JsonProperty)()
], Tag.prototype, "tag", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "unitaryPrefix", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "discriminator", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "concat", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "finalize", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "valid", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "pop", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "getCategory", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "getNamespace", void 0);
__decorate([
    (0, jackson_js_1.JsonIgnore)()
], Tag.prototype, "getAdditionalTokens", void 0);
Tag = Tag_1 = __decorate([
    (0, jackson_js_1.JsonSerialize)({ using: TagSerializer.serialize }),
    (0, jackson_js_1.JsonDeserialize)({ using: TagSerializer.deserialize })
], Tag);
exports.Tag = Tag;
//# sourceMappingURL=tag.js.map