/**
 * @constructor
**/
function Chatter(id) {
    /** @const @type {string} */
    this.id = id;
    /** @type {string} */
    this.name;
    /** @type {boolean} */
    this.deleted;
    /** @type {string} */
    this.status;
    /** @type {string} */
    this.realName;
    /** @type {boolean} */
    this.presence;
    /** @type {Object.<string, string>} */
    this.icons = {
        small: ""
        ,large: ""
    };
    /** @type {string} */
    this.email;
    /** @type {string} */
    this.firstName;
    /** @type {string} */
    this.lastName;
    /** @type {!Object.<string, Room>} */
    this.channels = {};
    /** @type {SelfPreferences|null} */
    this.prefs = null;
    /** @type {boolean} */
    this.isBot;
    /** @type {PrivateMessageRoom|null} */
    this.privateRoom = null;
    /** @type {number} */
    this.version = 0;
};

Chatter.prototype.toStatic = function(t) {
    return t >= this.version ? null : {
        "id": this.id
        ,"name": this.name
        ,"deleted": this.deleted
        ,"status": this.status
        ,"real_name": this.realName
        ,"isPresent": this.presence
        ,"isBot": this.isBot
        ,"profile": {
            "email": this.email
            ,"first_name": this.firstName
            ,"last_name": this.lastName
            ,"icon_small": this.icons.small
            ,"icon_large": this.icons.large
        }
    };
};

/**
 * @param {*} userData
 * @param {number} t
**/
Chatter.prototype.update = function(userData, t) {
    if (userData["name"] !== undefined) this.name = userData["name"];
    if (userData["deleted"] !== undefined) this.deleted = userData["deleted"];
    if (userData["status"] !== undefined) this.status = userData["status"];
    if (userData["real_name"] !== undefined)
        this.realName = userData["real_name"];
    else if (userData["profile"] && userData["profile"]["real_name"] !== undefined)
        this.realName = userData["profile"]["real_name"];
    if (userData["presence"] !== undefined)
        this.presence = userData["presence"] !== 'away';
    if (userData["isPresent"] !== undefined)
        this.presence = userData["isPresent"];
    if (userData["isBot"]) this.isBot = userData["isBot"];
    if (userData["profile"]) {
        this.icons.small = userData["profile"]["icon_small"];
        this.icons.large = userData["profile"]["icon_large"];
        this.email = userData["profile"]["email"];
        this.firstName = userData["profile"]["first_name"];
        this.lastName = userData["profile"]["last_name"];
    }
    this.version = Math.max(this.version, t);
};

/** @suppress {undefinedVars,checkTypes} */
(function() {
    if (typeof module !== "undefined") {
        module.exports.Chatter = Chatter;
    }
})();

