"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Appreciation = exports.Channel = void 0;
/**
 *  All Types of Appreciations to be setted on an item
 * @public
 * @enum {string}
 * @readonly
 */
var Appreciation;
(function (Appreciation) {
    /** Applause */
    Appreciation["Applause"] = "applause";
    /** Doubt */
    Appreciation["Doubt"] = "doubt";
    /** Fantastic */
    Appreciation["Fantastic"] = "fantastic";
    /** Happy */
    Appreciation["Happy"] = "happy";
    /** Like */
    Appreciation["Like"] = "like";
    /** None (no appreciation) */
    Appreciation["None"] = "none";
})(Appreciation || (exports.Appreciation = Appreciation = {}));
/**
 * @class
 * @name Appreciations
 * @public
 * @description
 * Number of applause, doubt, fantastic, happy and like appreciations for an item
 */
class Appreciations {
    // Serialize this object to string
    // <returns><see cref="String"/> as serialization result</returns>
    ToString() {
        let tab = " ";
        return ("Applause:[" + this.Applause + "] " + tab + "Doubt:[" + this.Doubt + "] " + tab + "Fantastic:[" + this.Fantastic + "] " + tab + "Happy:[" + this.Happy + "] " + tab + "Like:[" + this.Like + "]");
    }
}
/**
 * @class
 * @name Channel
 * @public
 * @description
 *  This class is used to represent a channel
 */
class Channel {
    /**
     * @this Channel
     */
    constructor(_name, _id, _visibility, _topic, _creatorId, _companyId, _creationDate, _users_count, _lastAvatarUpdateDate, _subscribed, _type, _invited, _category, _mode, _subscribers_count, _serverURL, _max_items = 0, _max_payload_size = 0, _pageIndex = 0, _isLoading = false, _complete = false, _users = [], _publishersRetreived = false, _loaded = false, _avatar, _userRole = 'none', _messageRetrieved = false, _messages = [], _deleted = false, _mute = false, _enable_comments = null, _max_comments = null, _max_payload_comment_size = null, _additionDate = null, _lastCheckDate, _max_payload_size_comment) {
        this.subscribed = false;
        this.type = "SIMPLE";
        this.invited = false;
        this.serverURL = "";
        this.pageIndex = 0;
        this.isLoading = false;
        this.complete = false;
        this.users = [];
        this.publishersRetreived = false;
        this.loaded = false;
        this.userRole = 'none';
        this.messageRetrieved = false;
        this.messages = [];
        this.deleted = false;
        this.mute = false;
        this.enable_comments = null;
        this.max_comments = null;
        this.max_payload_comment_size = null;
        this.additionDate = null;
        /**
         * @public
         * @property {string} name channel name
         *
         */
        this.name = _name;
        /**
         * @public
         * @property {string} id channel unique identifier
         *
         */
        this.id = _id;
        /**
         * @public
         * @property {string} visibility channel type/visibility<br>
         *        "private" : a « Pub » channel, only the owner may publish messages.<br>
         *                    Managed by owner, the only one who can add or remove users in a private channels.<br>
         *                    Can't be found by search.<br>
         *        "company" : « PubSub » channel (company users may join/leave)
         *                    May be found by search for users in the same company.<br>
         *        "public"  : « PubSub » public channel.
         *                    Only allowed users may create a "public" channel.
         *                    May be found by search for all users.<br>
         *
         */
        this.visibility = _visibility;
        /**
         * @public
         * @property {string} topic channel topic
         *
         */
        this.topic = _topic;
        /**
         * @public
         * @property {string} creatorId the creator rainbow user id
         *
         */
        this.creatorId = _creatorId;
        /**
         * @public
         * @property {string} companyId the channel rainbow company id
         *
         */
        this.companyId = _companyId;
        /**
         * @public
         * @property {Date} creationDate creation date of the channel (read only, set automatically during creation)
         *
         */
        this.creationDate = _creationDate;
        /**
         * @public
         * @property {string} type type of role of the user : owner / member / publisher
         *
         */
        this.type = _type;
        /**
         * @public
         * @property {number} users_count The number of users in the channel
         *
         */
        this.users_count = _users_count;
        /**
         * @public
         * @property {number} subscribers_count The number of subscribers in the channel
         *
         */
        this.subscribers_count = _subscribers_count;
        /**
         *  @public
         * @property {string} category the category channel
         *
         */
        this.category = _category;
        /**
         *  @public
         * @property {string} mode the category mode
         *
         */
        this.mode = _mode;
        /**
         *  @public
         * @property {number} max_items max # of items to persist. Default value : 30
         *
         */
        this.max_items = _max_items;
        /**
         *  @public
         * @property {number} max_payload_size max payload size in bytes. Default value : 60000
         *
         */
        this.max_payload_size = _max_payload_size;
        this.serverURL = _serverURL;
        /**
         *  @public
         * @property {string} lastAvatarUpdateDate date of last avatar change
         *
         */
        this.lastAvatarUpdateDate = _lastAvatarUpdateDate;
        let timestamp = this.lastAvatarUpdateDate ? "&ts=" + new Date(this.lastAvatarUpdateDate).getTime() : "";
        /**
         *  @public
         * @property {string} avatar The path of the channel avatar.
         *
         */
        this.avatar = this.serverURL + "/api/channel-avatar/" + _id + "?size=256" + timestamp;
        if (_subscribed !== undefined) {
            /**
             *  @public
             * @property {boolean} subscribed user subscription state
             *
             */
            this.subscribed = _subscribed;
        }
        if (_type !== undefined) {
            /**
             *  @public
             * @property {string} userRole the channel affiliation type of the requesting user. Possible values : owner, publisher, member
             *
             */
            this.userRole = _type;
        }
        if (_invited !== undefined) {
            /**
             *  @public
             * @property {boolean} invited the channel invitation state of the requesting user
             *
             */
            this.invited = _invited;
        }
        if (!this.mode) {
            switch (this.visibility) {
                case "company":
                    this.mode = "company_public";
                    break;
                case "public":
                    this.mode = "all_public";
                    break;
                case "private":
                    this.mode = "company_private";
                    break;
                default:
                    break;
            }
        }
        /**
         *  @public
         * @property {boolean} deleted Channel deleted.
         *
         */
        this.deleted = _deleted;
        /**
         *  @public
         * @property {boolean} mute current mute state
         *
         */
        this.mute = _mute;
        /**
         *  @public
         * @property {boolean} enable_comments enable comments for a channel. Default value : true
         *
         */
        this.enable_comments = _enable_comments;
        /**
         *  @public
         * @property {number} max_comments max # of comments for an item (-1 for infinite). Default value : -1
         *
         */
        this.max_comments = _max_comments;
        /**
         *  @public
         * @property {number} max_payload_comment_size max payload size in bytes for a comment. Default value : 60000
         *
         */
        this.max_payload_comment_size = _max_payload_comment_size;
        /**
         *  @public
         * @property {boolean} additionDate the invitation/membership date
         *
         */
        this.additionDate = _additionDate;
        /**
         *  @public
         * @property {string} lastCheckDate
         *
         */
        this.lastCheckDate = _lastCheckDate;
        /**
         *  @public
         * @property {number} max_payload_size_comment
         *
         */
        this.max_payload_size_comment = _max_payload_size_comment;
    }
    isNotMember() { return (this.userRole = "none"); }
    isOwner() { return (this.userRole === "owner"); }
    isPublisher() { return (this.subscribed && (this.userRole === "owner" || this.userRole === "publisher")); }
    isMember() { return this.userRole === "member"; }
    getAvatarSrc() { return (this.lastAvatarUpdateDate) ? this.avatar : "/resources/skins/rainbow/images/channels/default_channel_avatar.png"; }
    /**
     * @function
     * @public
     * @name updateChannel
     * @description
     * This method is used to update a channel from data object
     */
    updateChannel(data) {
        let that = this;
        if (data) {
            let channelproperties = Object.getOwnPropertyNames(that);
            //console.log("updateChannel update Channel with : ", data["id"]);
            Object.getOwnPropertyNames(data).forEach((val, idx, array) => {
                //console.log(val + " -> " + data[val]);
                if (channelproperties.find((el) => { return val == el; })) {
                    //console.log("WARNING : One property of the parameter of updateChannel method is not present in the Bubble class : ", val, " -> ", data[val]);
                    that[val] = data[val];
                }
                else {
                    //console.log("WARNING : One property of the parameter of updateChannel method is not present in the Channel class can not update Channel with : ", val, " -> ", data[val]);
                    /*
                    console.log("WARNING : One property of the parameter of updateChannel method is not present in the Channel class can not update Channel with : ");
                    // */
                }
            });
        }
        return this;
    }
    /**
     * @function
     * @public
     * @name ChannelFactory
     * @description
     * This method is used to create a channel from data object
     */
    static ChannelFactory() {
        return (data, serverURL) => {
            let channel = new Channel(data.name, data.id, data.visibility, data.topic, data.creatorId, data.companyId, data.creationDate, data.users_count, data.lastAvatarUpdateDate, data.subscribed, data.type, data.invited, data.category, data.mode, data.subscribers_count, serverURL, data.max_items, data.max_payload_size, data.pageIndex, data.isLoading, data.complete, data.users, data.publishersRetreived, data.loaded, data.avatar, data.userRole, data.messageRetrieved, data.messages, data.deleted, data.mute, data.enable_comments, data.max_comments, data.max_payload_comment_size, data.additionDate, data.lastCheckDate, data.max_payload_size_comment);
            if (data) {
                let channelproperties = Object.getOwnPropertyNames(channel);
                Object.getOwnPropertyNames(data).forEach((val, idx, array) => {
                    //console.log(val + " -> " + data[val]);
                    if (!channelproperties.find((el) => { return val == el; })) {
                        /*
                        //console.log("WARNING : One property of the parameter of ChannelFactory method is not present in the Channel class : ", val, " -> ", data[val]);
                        console.log("WARNING : One property of the parameter of ChannelFactory method is not present in the Channel class : ", val);
                        // */
                    }
                });
            }
            return channel;
        };
    }
}
exports.Channel = Channel;
module.exports.Channel = Channel;
module.exports.Appreciation = Appreciation;
//# sourceMappingURL=Channel.js.map