import {SubcommandData} from "../types"
import {ApplicationCommandOptionType, ApplicationCommandSubCommandData, ChatInputCommandInteraction} from "discord.js"
import {UsersTable} from "../../database/users.js"

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

    constructor({users, cleanUp}: { users: UsersTable, 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.getActiveSnowflakeIsAdmin(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...",
            })
        }
    }
}