package main

import (
	"fmt"
	"os"

	"v.io/lib/cmdline"

	"v.io/core/veyron/services/mgmt/device/impl"
	"v.io/core/veyron2"
	"v.io/core/veyron2/vlog"
)

var (
	installFrom string
	suidHelper  string
	agent       string
	initHelper  string
	singleUser  bool
	sessionMode bool
	initMode    bool
)

const deviceDirEnv = "VANADIUM_DEVICE_DIR"

func installationDir() string {
	if d := os.Getenv(deviceDirEnv); d != "" {
		return d
	}
	if d, err := os.Getwd(); err != nil {
		vlog.Errorf("Failed to get current dir: %v", err)
		return ""
	} else {
		return d
	}
}

var cmdInstall = &cmdline.Command{
	Run:      runInstall,
	Name:     "install",
	Short:    "Install the device manager.",
	Long:     fmt.Sprintf("Performs installation of device manager into %s (if the env var set), or into the current dir otherwise", deviceDirEnv),
	ArgsName: "[-- <arguments for device manager>]",
	ArgsLong: `
Arguments to be passed to the installed device manager`,
}

func init() {
	cmdInstall.Flags.StringVar(&installFrom, "from", "", "if specified, performs the installation from the provided application envelope object name")
	cmdInstall.Flags.StringVar(&suidHelper, "suid_helper", "", "path to suid helper")
	cmdInstall.Flags.StringVar(&agent, "agent", "", "path to security agent")
	cmdInstall.Flags.StringVar(&initHelper, "init_helper", "", "path to sysinit helper")
	cmdInstall.Flags.BoolVar(&singleUser, "single_user", false, "if set, performs the installation assuming a single-user system")
	cmdInstall.Flags.BoolVar(&sessionMode, "session_mode", false, "if set, installs the device manager to run a single session. Otherwise, the device manager is configured to get restarted upon exit")
	cmdInstall.Flags.BoolVar(&initMode, "init_mode", false, "if set, installs the device manager with the system init service manager")
}

func runInstall(cmd *cmdline.Command, args []string) error {
	if installFrom != "" {
		// TODO(caprita): Also pass args into InstallFrom.
		if err := impl.InstallFrom(installFrom); err != nil {
			vlog.Errorf("InstallFrom(%v) failed: %v", installFrom, err)
			return err
		}
		return nil
	}
	if suidHelper == "" {
		return cmd.UsageErrorf("--suid_helper must be set")
	}
	if agent == "" {
		return cmd.UsageErrorf("--agent must be set")
	}
	if initMode && initHelper == "" {
		return cmd.UsageErrorf("--init_helper must be set")
	}
	if err := impl.SelfInstall(installationDir(), suidHelper, agent, initHelper, singleUser, sessionMode, initMode, args, os.Environ(), cmd.Stderr(), cmd.Stdout()); err != nil {
		vlog.Errorf("SelfInstall failed: %v", err)
		return err
	}
	return nil
}

var cmdUninstall = &cmdline.Command{
	Run:   runUninstall,
	Name:  "uninstall",
	Short: "Uninstall the device manager.",
	Long:  fmt.Sprintf("Removes the device manager installation from %s (if the env var set), or the current dir otherwise", deviceDirEnv),
}

func runUninstall(cmd *cmdline.Command, _ []string) error {
	if err := impl.Uninstall(installationDir(), cmd.Stderr(), cmd.Stdout()); err != nil {
		vlog.Errorf("Uninstall failed: %v", err)
		return err
	}
	return nil
}

var cmdStart = &cmdline.Command{
	Run:   runStart,
	Name:  "start",
	Short: "Start the device manager.",
	Long:  fmt.Sprintf("Starts the device manager installed under from %s (if the env var set), or the current dir otherwise", deviceDirEnv),
}

func runStart(cmd *cmdline.Command, _ []string) error {
	if err := impl.Start(installationDir(), cmd.Stderr(), cmd.Stdout()); err != nil {
		vlog.Errorf("Start failed: %v", err)
		return err
	}
	return nil
}

var cmdStop = &cmdline.Command{
	Run:   runStop,
	Name:  "stop",
	Short: "Stop the device manager.",
	Long:  fmt.Sprintf("Stops the device manager installed under from %s (if the env var set), or the current dir otherwise", deviceDirEnv),
}

func runStop(cmd *cmdline.Command, _ []string) error {
	ctx, shutdown := veyron2.Init()
	defer shutdown()
	if err := impl.Stop(ctx, installationDir(), cmd.Stderr(), cmd.Stdout()); err != nil {
		vlog.Errorf("Stop failed: %v", err)
		return err
	}
	return nil
}

var cmdProfile = &cmdline.Command{
	Run:   runProfile,
	Name:  "profile",
	Short: "Dumps profile for the device manager.",
	Long:  "Prints the internal profile description for the device manager.",
}

func runProfile(cmd *cmdline.Command, _ []string) error {
	spec, err := impl.ComputeDeviceProfile()
	if err != nil {
		vlog.Errorf("ComputeDeviceProfile failed: %v", err)
		return err
	}
	fmt.Fprintf(cmd.Stdout(), "Profile: %#v\n", spec)
	desc, err := impl.Describe()
	if err != nil {
		vlog.Errorf("Describe failed: %v", err)
		return err
	}
	fmt.Fprintf(cmd.Stdout(), "Description: %#v\n", desc)
	return nil
}
