#include users.js

const MamiMessageAuthorInfo = function(self = false, user = null, id = null, name = null, colour = null, rank = null, avatar = null) {
    if(typeof self !== 'boolean')
        throw 'self must be a boolean';

    if(user === null) {
        id ??= '';
        name ??= '';
        colour ??= 'inherit';
        rank ??= 0;
        avatar ??= new MamiUserAvatarInfo(id);
    } else {
        if(typeof user !== 'object')
            throw 'user must be an object or null';

        id ??= user.id;
        name ??= user.name;
        colour ??= user.colour;
        rank ??= user.perms.rank;
        avatar ??= user.avatar;
    }

    if(typeof id !== 'string')
        throw 'id must be a string';
    if(typeof name !== 'string')
        throw 'name must be a string';
    if(typeof colour !== 'string')
        throw 'colour must be a string';
    if(typeof rank !== 'number')
        throw 'rank must be a number';
    if(typeof avatar !== 'object')
        throw 'avatar must be an object';

    return {
        get self() { return self; },

        get user() { return user; },
        get hasUser() { return user !== null; },

        get id() { return id; },
        get name() { return name; },
        get colour() { return colour; },
        get rank() { return rank; },
        get avatar() { return avatar; },
    };
};

const MamiMessageInfo = function(type, created = null, detail = null, id = '', author = null, channel = '', silent = false) {
    if(typeof type !== 'string')
        throw 'type must be a string';
    if(created === null)
        created = new Date;
    else if(!(created instanceof Date))
        throw 'created must be an instance of window.Date or null';
    if(typeof id !== 'string')
        throw 'id must be a string';
    if(typeof author !== 'object')
        throw 'author must be an object';
    if(typeof channel !== 'string')
        throw 'channel must be a string';
    if(typeof silent !== 'boolean')
        throw 'silent must be a boolean';

    return {
        get type() { return type; },
        get created() { return created; },
        get detail() { return detail; },
        get id() { return id; },
        get author() { return author; },
        get channel() { return channel; },
        get silent() { return silent; },
    };
};
