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

package task

import (
	"fmt"

	"git.secluded.site/lune/internal/completion"
	"github.com/spf13/cobra"
)

// AddCmd creates a new task. Exported for use by the add shortcut.
var AddCmd = &cobra.Command{
	Use:   "add NAME",
	Short: "Create a new task",
	Long: `Create a new task in Lunatask.

The task name is required. Use flags to set additional properties.
Use "-" as NAME to read the task name from stdin.`,
	Args: cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		// TODO: implement task creation
		name := args[0]
		fmt.Fprintf(cmd.OutOrStdout(), "Creating task: %s (not yet implemented)\n", name)

		return nil
	},
}

func init() {
	AddCmd.Flags().StringP("area", "a", "", "Area key (from config)")
	AddCmd.Flags().StringP("goal", "g", "", "Goal key (from config)")
	AddCmd.Flags().StringP("status", "s", "", "Status: later, next, started, waiting")
	AddCmd.Flags().StringP("note", "n", "", "Task note (use - for stdin)")
	AddCmd.Flags().IntP("priority", "p", 0, "Priority: -2 to 2")
	AddCmd.Flags().IntP("estimate", "e", 0, "Estimate in minutes (0-720)")
	AddCmd.Flags().StringP("motivation", "m", "", "Motivation: must, should, want")
	AddCmd.Flags().Int("eisenhower", 0, "Eisenhower quadrant: 1-4")
	AddCmd.Flags().String("schedule", "", "Schedule date (natural language)")

	_ = AddCmd.RegisterFlagCompletionFunc("area", completion.Areas)
	_ = AddCmd.RegisterFlagCompletionFunc("goal", completion.Goals)
	_ = AddCmd.RegisterFlagCompletionFunc("status",
		completion.Static("later", "next", "started", "waiting"))
	_ = AddCmd.RegisterFlagCompletionFunc("motivation",
		completion.Static("must", "should", "want"))
	_ = AddCmd.RegisterFlagCompletionFunc("eisenhower",
		completion.Static("1", "2", "3", "4"))
}
