package config

import (
	"context"

	"velox-bot/internal/commands/level/shared"
	"velox-bot/internal/db/services"

	"github.com/bwmarrin/discordgo"
)

func slvlToggleOption() *discordgo.ApplicationCommandOption {
	return &discordgo.ApplicationCommandOption{
		Type:        discordgo.ApplicationCommandOptionSubCommand,
		Name:        "toggle",
		Description: "Toggle the leveling system",
	}
}

func slvlToggleHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
	if !shared.RequireManageGuild(s, i) {
		return
	}
	if !shared.RequireLevelSettingsService(s, i) {
		return
	}
	guildID, ok := shared.ParseGuildID(s, i)
	if !ok {
		return
	}

	enabled, err := services.Global.LevelSettings.ToggleLevelSystem(context.Background(), guildID)
	if err != nil {
		shared.RespondEphemeral(s, i, "Failed to toggle leveling system.")
		return
	}
	status := "disabled"
	if enabled {
		status = "enabled"
	}
	shared.RespondEphemeral(s, i, "Leveling system "+status+" for this server.")
}

