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

package task

import (
	"fmt"

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

// UpdateCmd updates a task. Exported for potential use by shortcuts.
var UpdateCmd = &cobra.Command{
	Use:   "update ID",
	Short: "Update a task",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		id, err := validate.Reference(args[0])
		if err != nil {
			return err
		}

		// TODO: implement task update
		fmt.Fprintf(cmd.OutOrStdout(), "Updating task %s (not yet implemented)\n", id)

		return nil
	},
}

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

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