"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.CdmFolderCollection = void 0;
const internal_1 = require("../internal");
class CdmFolderCollection extends internal_1.CdmCollection {
    constructor(ctx, parentFolder) {
        super(ctx, parentFolder, internal_1.cdmObjectType.folderDef);
    }
    get owner() {
        return super.owner;
    }
    set owner(value) {
        super.owner = value;
    }
    /**
     * @inheritdoc
     */
    push(childFolderOrName, simpleRef = false) {
        const childFolder = super.push(childFolderOrName, simpleRef);
        this.addItemModifications(childFolder);
        return childFolder;
    }
    insert(index, childFolder) {
        this.addItemModifications(childFolder);
        super.insert(index, childFolder);
    }
    addItemModifications(childFolder) {
        childFolder.corpus = this.owner.corpus;
        childFolder.namespace = this.owner.namespace;
        childFolder.folderPath = `${this.owner.folderPath}${childFolder.name}/`;
        // TODO: At this point we should also propagate the root adapter into the child folder 
        // and all its sub-folders and contained documents. For now, don't add things to the
        // folder unless it's tied to an adapter root.
    }
    /**
     * @internal
     */
    getOrCreate(name) {
        let result;
        for (const folder of this.allItems) {
            if (name.toLowerCase() == folder.name.toLowerCase()) {
                // found our folder.
                result = folder;
                break;
            }
        }
        if (!result) {
            result = this.push(name);
        }
        return result;
    }
}
exports.CdmFolderCollection = CdmFolderCollection;
//# sourceMappingURL=CdmFolderCollection.js.map