import CommandBuilder from "../builders/command";

function volumeHandler(args, context) {
    if (args.length < 3) {
        return context.print(`Usage: volume <music/sfx/ambience> <0-100>`);
    }
    const value = parseInt(args[2]);
    if (value > 100 || value < 1) {
        return context.print(`No higher than 100 and no less than 1.`);
    }
    if (args[1] == "sfx") {
        context.output.sound.setSFXVolume(value/100);
    } else if (args[1] == "music") {
        context.output.sound.setMusicVolume(value/100);
    } else if (args[1] == "ambience") {
        context.output.sound.setAmbienceVolume(value/100);
    } else {
        return context.print(`Invalid channel. Either ambience, sfx or music is allowed.`);
    }
    context.print(`${args[1]} volume set to ${value}%`)
}

export default new CommandBuilder()
    .withName("volume")
    .withCategory("System")
    .withDescription("Adjust volume")
    .withArgument("select", "channel", false, "Audio channel")
    .withArgument("text", "level", false, "Volume level (1-100)")
    .withHandler(volumeHandler)
    .create();