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 __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var RelationResource_1;
import { JsonElementType, JsonObject, JsonProperty } from "ta-json";
import { EntityLink } from "../entity-link";
import Resource from "./resource";
let RelationResource = RelationResource_1 = class RelationResource extends Resource {
    constructor(init) {
        super();
        Object.assign(this, init);
    }
    /**
     * Merges two relation resources.
     *
     * This should be used for self referencing relations, where there can be no conflicts
     * between the two existing resources.
     * @param main - Source to use as defaults
     * @param toMerge - Source to use to set relation links
     */
    static merge(main, toMerge) {
        const result = new RelationResource_1({
            child: main.child,
            children: main.children,
            inheritsSecurity: main.inheritsSecurity,
            parent: main.parent,
            parents: main.parents,
            self: main.self,
        });
        if (toMerge.child != null) {
            result.child = toMerge.child;
        }
        if (toMerge.children != null) {
            result.children = toMerge.children;
        }
        if (toMerge.parent != null) {
            result.parent = toMerge.parent;
        }
        if (toMerge.parents != null) {
            result.parents = toMerge.parents;
        }
        return result;
    }
};
__decorate([
    JsonProperty("parents"),
    JsonElementType(EntityLink),
    __metadata("design:type", Array)
], RelationResource.prototype, "parents", void 0);
__decorate([
    JsonProperty("parent"),
    JsonElementType(EntityLink),
    __metadata("design:type", EntityLink)
], RelationResource.prototype, "parent", void 0);
__decorate([
    JsonProperty("children"),
    JsonElementType(EntityLink),
    __metadata("design:type", Array)
], RelationResource.prototype, "children", void 0);
__decorate([
    JsonProperty("child"),
    JsonElementType(EntityLink),
    __metadata("design:type", EntityLink)
], RelationResource.prototype, "child", void 0);
__decorate([
    JsonProperty("inherits_security"),
    __metadata("design:type", Boolean)
], RelationResource.prototype, "inheritsSecurity", void 0);
__decorate([
    JsonProperty("parent_total"),
    __metadata("design:type", Number)
], RelationResource.prototype, "parentTotal", void 0);
__decorate([
    JsonProperty("child_total"),
    __metadata("design:type", Number)
], RelationResource.prototype, "childTotal", void 0);
RelationResource = RelationResource_1 = __decorate([
    JsonObject(),
    __metadata("design:paramtypes", [Object])
], RelationResource);
export { RelationResource };
//# sourceMappingURL=relation-resource.js.map