typings/lib2/messagev2/field/singleSelectField.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SingleSelectField = exports.SingleSelectLayoutStyle = void 0;
const internal_1 = require("../internal");
/**
 * Represents the layout style for a single select field.
 */
var SingleSelectLayoutStyle;
(function (SingleSelectLayoutStyle) {
    SingleSelectLayoutStyle["list"] = "list";
    SingleSelectLayoutStyle["radioGroup"] = "radioGroup";
})(SingleSelectLayoutStyle = exports.SingleSelectLayoutStyle || (exports.SingleSelectLayoutStyle = {}));
/**
 * Represents a single select field.
 * @extends EditableField
 */
class SingleSelectField extends internal_1.EditableField {
    /**
     * Creates an instance of the SingleSelectField class.
     * @param {string} id The unique identifier of the field.
     * @param {string} label The label of the field.
     * @param {SelectFieldOption[]} options The options to of the field.
     */
    constructor(id, label, options) {
        super(id);
        this.displayType = 'singleSelect';
        this.options = [];
        this.layoutStyle = SingleSelectLayoutStyle.list;
        this.setLabel(label);
        if (options) {
            this.setOptions(options);
        }
    }
    /**
     * Deserialize nested object properties into corresponding class instances
     */
    deserializeNestedProperties() {
        super.deserializeNestedProperties();
        if (this.options) {
            this.options = internal_1.MessageUtil.deserializeSelectFieldOptions(this.options);
        }
    }
    /**
     * Gets the options of the field.
     * @returns {SelectFieldOption[]} The options of the field.
     */
    getOptions() {
        return this.options;
    }
    /**
     * Sets the options of the field.
     * @param {SelectFieldOption[]} options The options to set.
     * @returns The updated instance of the SingleSelectField.
     */
    setOptions(options) {
        this.options = options;
        return this;
    }
    /**
     * Add an option.
     * @param {SelectFieldOption} option The option to add.
     * @returns The updated instance of the SingleSelectField.
     */
    addOption(option) {
        this.options.push(option);
        return this;
    }
    /**
     * Gets the default value of the field.
     * @returns {any} The default value of the field.
     */
    getDefaultValue() {
        return this.defaultValue;
    }
    /**
     * Sets the default value of the field.
     * @param {any} defaultValue The default value to set.
     * @returns The updated instance of the SingleSelectField.
     */
    setDefaultValue(defaultValue) {
        this.defaultValue = defaultValue;
        return this;
    }
    /**
     * Gets the layout style of the field.
     * @returns {SingleSelectLayoutStyle} The layout style of the field.
     */
    getLayoutStyle() {
        return this.layoutStyle;
    }
    /**
     * Sets the layout style of the field.
     * @param {SingleSelectLayoutStyle} layoutStyle The layout style to set.
     * @returns The updated instance of the SingleSelectField.
     */
    setLayoutStyle(layoutStyle) {
        this.layoutStyle = layoutStyle;
        return this;
    }
}
exports.SingleSelectField = SingleSelectField;