"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChildRelationBase = exports.RelationBase = void 0;
const guard_1 = __importDefault(require("../../guard"));
const entity_load_configuration_1 = require("../querying/entity-load-configuration");
const member_1 = require("./member");
const member_definition_type_1 = require("./member-definition-type");
const relation_role_1 = require("./relation-role");
class RelationBase extends member_1.MemberBase {
    constructor(name, properties = null, client) {
        super(name, member_definition_type_1.MemberDefinitionType.Relation);
        this.client = client;
        this.properties = properties == null ? {} : properties;
    }
    setIdentifiersAsync(identifiers) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a;
            guard_1.default.arrayNoneNullOrEmptyString(identifiers);
            guard_1.default.notNullOrUndefined(this.client);
            const entities = yield this.client.entities.getManyAsync(identifiers, entity_load_configuration_1.EntityLoadConfiguration.Minimal);
            this.setIds((_a = entities === null || entities === void 0 ? void 0 : entities.filter(x => x.id !== null).map(x => x.id)) !== null && _a !== void 0 ? _a : []);
        });
    }
    getTypeName() {
        return relation_role_1.RelationRole[this.role];
    }
    static isChildRelation(r) {
        return r.role === relation_role_1.RelationRole.Child;
    }
    static isChildToOneParentRelation(r) {
        return r.role === relation_role_1.RelationRole.Child && !r.isMultiValue;
    }
    static isChildToManyParentsRelation(r) {
        return r.role === relation_role_1.RelationRole.Child && r.isMultiValue;
    }
    static isParentRelation(r) {
        return r.role === relation_role_1.RelationRole.Parent;
    }
    static isParentToOneChildRelation(r) {
        return r.role === relation_role_1.RelationRole.Parent && !r.isMultiValue;
    }
    static isParentToManyChildrenRelation(r) {
        return r.role === relation_role_1.RelationRole.Parent && r.isMultiValue;
    }
}
exports.RelationBase = RelationBase;
class ChildRelationBase extends RelationBase {
    constructor(name, properties, client) {
        super(name, properties, client);
        this.inheritsSecurity = true;
    }
}
exports.ChildRelationBase = ChildRelationBase;
//# sourceMappingURL=relation.js.map