// cmd/cli/user/get.go
package user

import (
	"fmt"
	"studia/internal/config"
	"studia/internal/database"
	"studia/internal/user"

	"github.com/spf13/cobra"
)

var email string

var getCmd = &cobra.Command{

	Use:   "get",
	Short: "Get user by ID",
	RunE: func(cmd *cobra.Command, args []string) error {
		cfg := config.New()

		cfg.DatabaseHost = "192.168.178.171"
		cfg.DatabasePort = "5432"
		cfg.DatabaseUser = "admin"
		cfg.DatabasePassword = "12345678"
		cfg.DatabaseName = "studia"

		database := database.New(cfg)

		user, err := user.GetUserByEmail(database, email)
		if err != nil {
			return err
		}

		fmt.Printf("ID: %d\nEmail: %s\nName: %s\n",
			user.ID, user.Email, user.Username)
		return nil
	},
}

func init() {
	getCmd.Flags().StringVar(&email, "email", "", "user email")
	getCmd.MarkFlagRequired("email")
}
