"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureLowercaseOrgUrlKeySlugAndKeyword = ensureLowercaseOrgUrlKeySlugAndKeyword;
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
const sharedMigrations_1 = require("../../core/_internal/sharedMigrations");
const util_1 = require("../../util");
/**
 * Fix issues caused by mixed case orgUrlKeys in the past.
 * Problems include:
 * - orgUrlKey not being lowercase
 * - slug getting the downcased orgUrlKey prepended to it multiple times
 * - slug typekeyword having an entry with the orgUrlKey prepended to it multiple times
 * @param model
 * @returns
 */
function ensureLowercaseOrgUrlKeySlugAndKeyword(model) {
    const clone = (0, util_1.cloneObject)(model);
    const slug = clone.item.properties.slug || "";
    const orgUrlKey = clone.item.properties.orgUrlKey || "";
    const resp = (0, sharedMigrations_1.migrateSlugAndOrgUrlKey)(slug, orgUrlKey, clone.item.typeKeywords);
    if (resp.slug) {
        // Ensure the slug is set in the properties
        clone.item.properties.slug = resp.slug;
    }
    if (resp.orgUrlKey) {
        clone.item.properties.orgUrlKey = resp.orgUrlKey;
    }
    clone.item.typeKeywords = resp.typeKeywords;
    return clone;
}
//# sourceMappingURL=ensureLowercaseOrgUrlKeySlugAndKeyword.js.map