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

export class CharacterCreateCommand extends SubcommandData {
    readonly definition: ApplicationCommandSubCommandData = {
        name: "create",
        type: ApplicationCommandOptionType.Subcommand,
        description: "Begins the process of creating a new character. Omit parameters for interactive process.",
        options: [
            {
                name: "name",
                type: ApplicationCommandOptionType.String,
                description: "The character's name, 1-20 characters. You can change this later.",
                required: false,
                maxLength: 20,
                minLength: 1,
            },
            {
                name: "title",
                type: ApplicationCommandOptionType.String,
                description: "The character's title, with @@ where your character's name goes. @@ alone means no title.",
                required: false,
                maxLength: 30,
                minLength: 2,
            },
            {
                name: "pronouns",
                type: ApplicationCommandOptionType.String,
                description: "Your character's pronouns. Don't worry, you can change this later.",
                required: false,
                autocomplete: true,
            },
            {
                name: "gender",
                type: ApplicationCommandOptionType.String,
                description: "Your character's pronouns. Don't worry, you can change this later.",
                required: false,
                maxLength: 20,
                minLength: 1,
            },
            {
                name: "difficulty",
                type: ApplicationCommandOptionType.String,
                description: "The difficulty of reformation. Don't worry, you can change this later.",
                required: false,
                autocomplete: true,
            },
            {
                name: "preference",
                type: ApplicationCommandOptionType.String,
                description: "What role(s) your character is able to play in vore. Don't worry, you can change this later.",
                required: false,
                autocomplete: true,
            },
            {
                name: "types",
                type: ApplicationCommandOptionType.String,
                description: "The type or types that describe your character. Don't worry, you can change this later.",
                required: false,
                autocomplete: true,
            },
            {
                name: "stats",
                type: ApplicationCommandOptionType.String,
                description: "Slash(/)-delimited base stats: Confidence/Health/Stamina/Brawn/Durability/Intensity/Resilience/Speed",
                required: false,
            },
        ],
    }
    private readonly _users: UserTable

    constructor({users}: { users: UserTable }) {
        super()
        this._users = users
    }

    async execute(b: ChatInputCommandInteraction) {
        await b.deferReply({ephemeral: true})
        // create database interfacing code, using this format:
        // INSERT INTO character_creation () VALUES () ON CONFLICT DO UPDATE SET (excluded.field IS NULL ? field : excluded.field)
        // then prompt the user to fill in the first null field, using a modal to input the text fields
        await b.followUp({
            ephemeral: true,
            content: "Zz... mn?",
        })
    }
}