"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlashCommandBuilder = void 0;
const tslib_1 = require("tslib");
const ts_mixer_1 = require("ts-mixer");
const Assertions_1 = require("./Assertions");
const CommandOptions_1 = require("./mixins/CommandOptions");
const NameAndDescription_1 = require("./mixins/NameAndDescription");
const SlashCommandSubcommands_1 = require("./SlashCommandSubcommands");
let SlashCommandBuilder = class SlashCommandBuilder {
    constructor() {
        /**
         * The name of this slash command
         */
        Object.defineProperty(this, "name", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: undefined
        });
        /**
         * The description of this slash command
         */
        Object.defineProperty(this, "description", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: undefined
        });
        /**
         * The options of this slash command
         */
        Object.defineProperty(this, "options", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: []
        });
        /**
         * Whether the command is enabled by default when the app is added to a guild
         * @default true
         */
        Object.defineProperty(this, "defaultPermission", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: undefined
        });
    }
    /**
     * Returns the final data that should be sent to Discord.
     *
     * **Note:** Calling this function will validate required properties based on their conditions.
     */
    toJSON() {
        Assertions_1.validateRequiredParameters(this.name, this.description, this.options);
        return {
            name: this.name,
            description: this.description,
            options: this.options.map((option) => option.toJSON()),
            default_permission: this.defaultPermission,
        };
    }
    /**
     * Sets whether the command is enabled by default when the application is added to a guild.
     *
     * **Note**: If set to `false`, you will have to later have to `PUT` the permissions for this command.
     * @param value Whether or not to enable this command by default
     *
     * @see https://discord.com/developers/docs/interactions/slash-commands#permissions
     */
    setDefaultPermission(value) {
        // Assert the value matches the conditions
        Assertions_1.validateDefaultPermission(value);
        Reflect.set(this, 'defaultPermission', value);
        return this;
    }
    /**
     * Adds a new subcommand group to this command
     * @param input A function that returns a subcommand group builder, or an already built builder
     */
    addSubcommandGroup(input) {
        const { options } = this;
        // First, assert options conditions - we cannot have more than 25 options
        Assertions_1.validateMaxOptionsLength(options);
        // Get the final result
        const result = typeof input === 'function' ? input(new SlashCommandSubcommands_1.SlashCommandSubcommandGroupBuilder()) : input;
        Assertions_1.assertReturnOfBuilder(result, SlashCommandSubcommands_1.SlashCommandSubcommandGroupBuilder);
        // Push it
        options.push(result);
        return this;
    }
    /**
     * Adds a new subcommand to this command
     * @param input A function that returns a subcommand builder, or an already built builder
     */
    addSubcommand(input) {
        const { options } = this;
        // First, assert options conditions - we cannot have more than 25 options
        Assertions_1.validateMaxOptionsLength(options);
        // Get the final result
        const result = typeof input === 'function' ? input(new SlashCommandSubcommands_1.SlashCommandSubcommandBuilder()) : input;
        Assertions_1.assertReturnOfBuilder(result, SlashCommandSubcommands_1.SlashCommandSubcommandBuilder);
        // Push it
        options.push(result);
        return this;
    }
};
SlashCommandBuilder = tslib_1.__decorate([
    ts_mixer_1.mix(CommandOptions_1.SharedSlashCommandOptions, NameAndDescription_1.SharedNameAndDescription)
], SlashCommandBuilder);
exports.SlashCommandBuilder = SlashCommandBuilder;
//# sourceMappingURL=SlashCommandBuilder.js.map