package help

import (
	"log"

	"github.com/bwmarrin/discordgo"
)

var Help = &discordgo.ApplicationCommand{
	Name:        "help",
	Description: "Get help with the bot",
}

func HelpHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
	s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
		Type: discordgo.InteractionResponseChannelMessageWithSource,
		Data: &discordgo.InteractionResponseData{
			Content: "Check your DMs for help.",
			Flags:   discordgo.MessageFlagsEphemeral,
		},
	})

	userID := ""

	// check if command is run in a guild
	if i.Member != nil {
		userID = i.Member.User.ID
	} else {
		userID = i.Interaction.User.ID
	}

	dmChannel, err := s.UserChannelCreate(userID)
	if err != nil {
		log.Printf("Error creating DM channel: %v", err)
		return
	}

	author := discordgo.MessageEmbedAuthor{
		Name: "Velox Bot",
		URL:  "https://gitea.fernandovideira.com/FernandoJVideira/velox-bot",
	}

	embed := &discordgo.MessageEmbed{
		Title:       "Velox Bot Help",
		Description: "Here is the help for the bot.",
		Color:       0xFFA500,
		Fields: []*discordgo.MessageEmbedField{
			{
				Name:  "Fun Commands",
				Value: "Here are the fun commands for the bot.",
			},
			{
				Name:  "/ping",
				Value: "Pong!",
			},
			{
				Name:  "/help",
				Value: "Get help with the bot.",
			},
			{
				Name:  "Leveling System",
				Value: `The leveling system is a system that allows users to gain XP and level up. The system is based on the amount of messages sent in a server. The more messages you send, the more XP you gain. The more XP you gain, the higher your level will be. The leveling system is disabled by default, however you can enable/disable it by using the /slvl toggle command. You can also configure the leveling system by using the /slvl command.`,
			},
			{
				Name:  "/slvl toggle",
				Value: "Toggle the leveling system.",
			},
			{
				Name:  "/slvl set",
				Value: "Set the level of a user.",
			},
		},
		Author: &author,
	}

	s.ChannelMessageSendEmbed(dmChannel.ID, embed)
}
