Umi.User = function(userId, userName, userColour, userPerms) {
    userId = (userId || '').toString();
    userColour = (userColour || 'inherit').toString();

    const userIdInt = parseInt(userId);

    const setName = function(name) {
        userName = (name || '').toString().replace('&lt;', '<').replace('&gt;', '>');
    };
    setName(userName);

    const setColour = function(colour) {
        userColour = (colour || 'inherit').toString();
    };
    setColour(userColour);

    let userRank = 0;
    let canBan = false;
    let canSetNickName = false;
    let canCreateChannel = false;

    const setPerms = function(perms) {
        perms = (perms || '').toString();
        perms = perms.split(perms.includes("\f") ? "\f" : ' ');

        userRank = parseInt(perms[0] || 0);
        canBan = (perms[1] || '0') === '1';
        canSetNickName = (perms[3] || '0') === '1';
        canCreateChannel = (perms[4] || '0') === '1' || (perms[4] || '0') === '2';
    };
    setPerms(userPerms);

    let avatarTime = Date.now();

    return {
        getId: function() { return userId; },
        getIdInt: function() { return userIdInt; },

        getName: function() { return userName; },
        setName: setName,

        getColour: function() { return userColour; },
        setColour: setColour,

        setPermissions: setPerms,

        getRank: function() { return userRank; },
        isCurrentUser: function() { return Umi.User.currentUser && Umi.User.currentUser.userId === userId; },
        canBan: function() { return canBan; },
        canSilence: function() { return canBan; },
        canCreateChannel: function() { return canCreateChannel; },
        canSetNickName: function() { return canSetNickName; },
        getAvatarTime: function() { return avatarTime; },
        bumpAvatarTime: function() { avatarTime = Date.now(); },

        isBot: function() { return userId === '-1'; },
    };
};
Umi.User.currentUser = undefined;
Umi.User.hasCurrentUser = function() { return Umi.User.currentUser !== undefined; };
Umi.User.getCurrentUser = function() { return Umi.User.currentUser; };
Umi.User.setCurrentUser = function(user) { Umi.User.currentUser = user; };
Umi.User.isCurrentUser = function(user) {
    return Umi.User.currentUser !== undefined
        && (Umi.User.currentUser === user || Umi.User.currentUser.getId() === user.getId());
};
