/**
 * @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 {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 // FIXME move to profile (or remove profile)
        ,"isPresent": this.presence
        ,"isBot": this.isBot
        ,"profile": {
            "email": this.email
            ,"first_name": this.firstName
            ,"last_name": this.lastName
        }
    };
};

/**
 * @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.email = userData["profile"]["email"];
        this.firstName = userData["profile"]["first_name"];
        this.lastName = userData["profile"]["last_name"];
    }
    this.version = Math.max(this.version, t);
};

Chatter.prototype.getSmallIcon = function() {
    return "api/avatar?user=" +this.id;
};

Chatter.prototype.getLargeIcon = function() {
    return "api/avatar?size=l&user=" +this.id;
};

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

