"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateInitiativeAddDefaultCatalog = migrateInitiativeAddDefaultCatalog;
const get_prop_1 = require("../../objects/get-prop");
const util_1 = require("../../util");
/**
 * Apply the default catalog to the initiative model
 * @param model
 * @returns
 */
function migrateInitiativeAddDefaultCatalog(initiative) {
    if (initiative.schemaVersion && initiative.schemaVersion >= 1.1) {
        return initiative;
    }
    else {
        const clone = (0, util_1.cloneObject)(initiative);
        // v0 of initiatives did not have a catalog, so we need to add one
        // based on the content group associated with the initiative
        const groupId = (0, get_prop_1.getProp)(clone, "contentGroupId");
        const group = groupId ? [groupId] : [];
        const catalog = {
            schemaVersion: 1,
            title: "Default Initiative Catalog",
            scopes: {
                item: {
                    targetEntity: "item",
                    filters: [
                        {
                            predicates: [
                                {
                                    group,
                                },
                            ],
                        },
                    ],
                },
            },
            collections: [],
        };
        clone.catalog = catalog;
        // set the schema version
        clone.schemaVersion = 1.1;
        return clone;
    }
}
//# sourceMappingURL=migrateInitiativeAddDefaultCatalog.js.map