models/communities/PollOption.js

import MediaAttachment from './../MediaAttachment.js';

export default class PollOption {
    /**
     * Creates a new PollOption instance.
     *
     * @constructor PollOption
     * @param {Object} optionMap - Option parameters
     * @param {string} optionMap.optionId - Option ID
     * @param {string} [optionMap.text] - Option text
     * @param {MediaAttachment} [optionMap.attachment] - Option attachment
     * @param {number} [optionMap.voteCount=0] - Amount of votes for this option
     * @param {boolean} [optionMap.isVotedByMe=false] - True is current user voted this option
     */
    constructor(optionMap) {
        this.optionId = optionMap.optionId;
        this.text = optionMap.text;
        this.voteCount = optionMap.voteCount || 0;
        this.isVotedByMe = optionMap.isVotedByMe === true;
        const rawAttachment = optionMap.attachment;
        if (rawAttachment !== undefined && rawAttachment != null) {
            const attachment = new MediaAttachment(rawAttachment);
            this.attachment = attachment;
        }
        Object.freeze(this);
    }
}