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

package journal

import (
	"fmt"

	"github.com/spf13/cobra"
)

// AddCmd creates a journal entry. Exported for use by the jrnl shortcut.
var AddCmd = &cobra.Command{
	Use:   "add [CONTENT]",
	Short: "Create a journal entry",
	Long: `Create a journal entry in Lunatask.

Creates an entry for today by default. Use --date to specify another date.
Use "-" as CONTENT to read from stdin.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		date, _ := cmd.Flags().GetString("date")
		if date == "" {
			date = "today"
		}

		// TODO: implement journal entry creation
		content := ""
		if len(args) > 0 {
			content = args[0]
		}
		fmt.Fprintf(cmd.OutOrStdout(), "Creating journal entry for %s (not yet implemented)\n", date)
		if content != "" {
			fmt.Fprintf(cmd.OutOrStdout(), "Content: %s\n", content)
		}

		return nil
	},
}

func init() {
	AddCmd.Flags().StringP("date", "d", "", "Entry date (natural language, default: today)")
	AddCmd.Flags().StringP("name", "n", "", "Entry title (default: weekday name)")
}
