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

package person

import (
	"fmt"

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

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

		force, _ := cmd.Flags().GetBool("force")
		if !force {
			if !ui.Confirm(fmt.Sprintf("Delete person %s?", id)) {
				fmt.Fprintln(cmd.OutOrStdout(), "Cancelled")

				return nil
			}
		}

		// TODO: implement person deletion
		fmt.Fprintf(cmd.OutOrStdout(), "Deleting person %s (not yet implemented)\n", id)

		return nil
	},
}

func init() {
	DeleteCmd.Flags().BoolP("force", "f", false, "Skip confirmation prompt")
}
