package oxide

import (
	"os"
	"path/filepath"
)

// OxideStatus represents a progress update published to NATS during Oxide installation.
// The frontend listens on corrosion.{license_id}.oxide.status for these messages.
type OxideStatus struct {
	Stage     string `json:"stage"`
	Progress  int    `json:"progress"`
	Message   string `json:"message"`
	Error     string `json:"error,omitempty"`
	Timestamp string `json:"timestamp"`
}

// Valid installation stages:
//   fetching_release - Querying GitHub API for latest Oxide.Rust release
//   downloading      - Downloading the Oxide zip file
//   installing       - Extracting zip over server directory
//   restarting       - Restarting the game server to load Oxide
//   complete         - Oxide installation finished successfully
//   failed           - Installation failed at some stage

// CheckOxideInstalled returns true if the oxide/ directory exists in the
// server installation directory, indicating that Oxide/uMod has been installed.
func CheckOxideInstalled(installDir string) bool {
	_, err := os.Stat(filepath.Join(installDir, "server", "oxide"))
	return err == nil
}
