"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.StringEnumPolicy = void 0; const basePolicy_1 = require("./basePolicy"); const render_1 = require("./render"); const types_1 = require("./types"); class StringEnumPolicy extends basePolicy_1.BasePolicy { enum_; enumDescriptions; static from(category, policy) { const { type, name, minimumVersion, enum: enumValue, localization } = policy; if (type !== 'string') { return undefined; } const enum_ = enumValue; if (!enum_) { return undefined; } if (!localization.enumDescriptions || !Array.isArray(localization.enumDescriptions) || localization.enumDescriptions.length !== enum_.length) { throw new Error(`Invalid policy data: enumDescriptions must exist and have the same length as enum_ for policy "${name}".`); } const enumDescriptions = localization.enumDescriptions.map((e) => ({ nlsKey: e.key, value: e.value })); return new StringEnumPolicy(name, { moduleName: '', name: { nlsKey: category.name.key, value: category.name.value } }, minimumVersion, { nlsKey: localization.description.key, value: localization.description.value }, '', enum_, enumDescriptions); } constructor(name, category, minimumVersion, description, moduleName, enum_, enumDescriptions) { super(types_1.PolicyType.StringEnum, name, category, minimumVersion, description, moduleName); this.enum_ = enum_; this.enumDescriptions = enumDescriptions; } renderADMXElements() { return [ ``, ...this.enum_.map((value, index) => ` ${value}`), `` ]; } renderADMLStrings(translations) { return [ ...super.renderADMLStrings(translations), ...this.enumDescriptions.map(e => this.renderADMLString(e, translations)) ]; } renderADMLPresentationContents() { return ``; } renderJsonValue() { return this.enum_[0]; } renderProfileValue() { return `${this.enum_[0]}`; } renderProfileManifestValue(translations) { return `pfm_default ${this.enum_[0]} pfm_description ${(0, render_1.renderProfileString)(this.name, this.moduleName, this.description, translations)} pfm_name ${this.name} pfm_title ${this.name} pfm_type string pfm_range_list ${this.enum_.map(e => `${e}`).join('\n ')} `; } } exports.StringEnumPolicy = StringEnumPolicy; //# sourceMappingURL=stringEnumPolicy.js.map