const desc = "authenticate";
const usages = " - auth <hash>";
const trustLevel = 0;
const config = require("../config.json");

function inject (client, packet) {    
    const command = ((args) => {
        switch (args[0]) {
            case "" + client.trustedHash + "":
                if (!client.trusted.includes(packet.sender)) {
                    client.trusted.push(packet.sender);
                    client.bcraw(`${config.publicColor}You have been authenticated as a ${config.trustedColor}trusted user${config.publicColor}.`);
                } else {
                    client.cmdError("Nothing changed. You are already authed for trusted");
                }
                client.createHash("trusted");
            break;

            case "" + client.ownerHash + "":
                if (!client.owner.includes(packet.sender)) {
                    client.owner.push(packet.sender);
                    client.bcraw(`${config.publicColor}You have been authenticated as the ${config.trustedColor}owner${config.publicColor}.`);
                } else {
                    client.cmdError("Nothing changed. You are already authed for owner");
                }
                client.createHash("owner");
            break;

            default:
                client.cmdError("Invalid hash");
            break;
        }
    })
    client.runCommand = command;
    return command;
}

module.exports = { inject, desc, usages, trustLevel };