import Command from '../command';

export default class CommandBuilder {
    constructor() {
        this.command = new Command();
    }

    withName(name) {
        this.command.name = name;
        return this;
    }

    withAliases(aliases) {
        this.command.aliases = Array.isArray(aliases) ? aliases : [aliases];
        return this;
    }

    withCategory(category) {
        this.command.category = category;
        return this;
    }

    withDescription(description) {
        this.command.description = description;
        return this;
    }

    withArguments(args) {
        this.command.arguments = args;
        return this;
    }

    withArgument(type, name, optional = false, description = '') {
        if (!this.command.arguments) {
            this.command.arguments = [];
        }
        this.command.arguments.push({
            type,
            name,
            optional,
            description
        });
        return this;
    }

    withHandler(handler) {
        this.command.handler = handler;
        return this;
    }

    isAsync(value = true) {
        this.command.async = value;
        return this;
    }

    withMetadata(metadata) {
        Object.assign(this.command, metadata);
        return this;
    }

    create() {
        return this.command;
    }
}