import {SubcommandData} from "../types"
import {ApplicationCommandOptionType, ApplicationCommandSubCommandData, ChatInputCommandInteraction} from "discord.js"
import {UsersManager} from "../../managers/users";

export class BotShutdownCommand extends SubcommandData {
    private readonly _users: UsersManager
    private readonly _cleanUp: () => Promise<void>

    constructor({users, cleanUp}: { users: UsersManager, cleanUp(): Promise<void> }) {
        super()
        this._users = users
        this._cleanUp = cleanUp
    }

    readonly definition: ApplicationCommandSubCommandData = {
        name: "shutdown",
        type: ApplicationCommandOptionType.Subcommand,
        description: "Tells the bot to shut down.",
    }

    async execute(b: ChatInputCommandInteraction): Promise<void> {
        if (await this._users.isSnowflakeAdmin(b.user.id)) {
            await b.reply({
                ephemeral: true,
                content: "Good night =w=",
            })
            b.client.user.presence.set({
                status: "invisible",
                activities: [],
            })
            await this._cleanUp()
        } else {
            await b.reply({
                ephemeral: true,
                content: "Heeey... I don't gotta do what you say...",
            })
        }
    }
}