package main

import (
	"os"
	"qvm/internal/logging"
	"qvm/internal/vm"

	"github.com/spf13/cobra"
)

var stopCmd = &cobra.Command{
	Use:   "stop",
	Short: "Stop the VM",
	Long: `Gracefully shut down the running VM.

Sends ACPI shutdown signal and waits up to 30 seconds.
Force kills if timeout is exceeded.`,
	Run: func(cmd *cobra.Command, args []string) {
		if !vm.IsRunning() {
			logging.Info("VM is not running")
			return
		}

		logging.Info("Stopping VM...")

		result := vm.Stop()
		if result.IsError() {
			logging.Error(result.Error().Error())
			os.Exit(1)
		}

		logging.Info("VM stopped successfully")
	},
}
