"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schema_1 = require("../schema"); const utils_1 = require("../utils"); class ChoiceSchema extends schema_1.Schema { constructor(parameters) { super(parameters); this._choices = utils_1.mapFromArray(parameters.choices.map(choice => choice && typeof choice === 'object' ? choice : { value: choice }), 'value'); } expected({ descriptor }) { const choiceValues = Array.from(this._choices.keys()) .map(value => this._choices.get(value)) .filter(choiceInfo => !choiceInfo.deprecated) .map(choiceInfo => choiceInfo.value) .sort(utils_1.comparePrimitive) .map(descriptor.value); const head = choiceValues.slice(0, -2); const tail = choiceValues.slice(-2); return head.concat(tail.join(' or ')).join(', '); } validate(value) { return this._choices.has(value); } deprecated(value) { const choiceInfo = this._choices.get(value); return choiceInfo && choiceInfo.deprecated ? { value } : false; } forward(value) { const choiceInfo = this._choices.get(value); return choiceInfo ? choiceInfo.forward : undefined; } redirect(value) { const choiceInfo = this._choices.get(value); return choiceInfo ? choiceInfo.redirect : undefined; } } exports.ChoiceSchema = ChoiceSchema;