// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

// Package cmd provides the lune CLI commands.
package cmd

import (
	"context"
	"os"

	"git.secluded.site/lune/cmd/area"
	"git.secluded.site/lune/cmd/goal"
	"git.secluded.site/lune/cmd/habit"
	initcmd "git.secluded.site/lune/cmd/init"
	"git.secluded.site/lune/cmd/journal"
	"git.secluded.site/lune/cmd/note"
	"git.secluded.site/lune/cmd/person"
	"git.secluded.site/lune/cmd/task"
	"github.com/charmbracelet/fang"
	"github.com/spf13/cobra"
)

var (
	version = "dev"
	commit  = "none"
)

var rootCmd = &cobra.Command{
	Use:   "lune",
	Short: "A delightful CLI for Lunatask",
	Long: `lune is a command-line interface for Lunatask, the encrypted
all-in-one productivity app for tasks, habits, journaling, and more.

Run 'lune init' to configure your access token and get started.`,
	SilenceUsage:  true,
	SilenceErrors: true,
}

func init() {
	rootCmd.AddGroup(&cobra.Group{ID: "resources", Title: "Resources"})
	rootCmd.AddGroup(&cobra.Group{ID: "shortcuts", Title: "Shortcuts"})

	rootCmd.AddCommand(initcmd.Cmd)
	rootCmd.AddCommand(pingCmd)

	rootCmd.AddCommand(area.Cmd)
	rootCmd.AddCommand(goal.Cmd)
	rootCmd.AddCommand(task.Cmd)
	rootCmd.AddCommand(note.Cmd)
	rootCmd.AddCommand(person.Cmd)
	rootCmd.AddCommand(journal.Cmd)
	rootCmd.AddCommand(habit.Cmd)

	rootCmd.AddCommand(addCmd)
	rootCmd.AddCommand(doneCmd)
	rootCmd.AddCommand(jrnlCmd)
}

// Execute runs the root command with Fang styling.
func Execute(ctx context.Context) error {
	return fang.Execute(
		ctx,
		rootCmd,
		fang.WithVersion(version),
		fang.WithCommit(commit),
		fang.WithNotifySignal(os.Interrupt),
	)
}
