package platform

import (
	"os"
	"os/user"
	"runtime"
	"strconv"
)

// GetEffectiveUID returns the effective user ID on Unix-like systems
func GetEffectiveUID() int {
	if runtime.GOOS == "windows" {
		return -1
	}
	return os.Geteuid()
}

// IsRoot returns true if running as root (Unix-like systems)
func IsRoot() bool {
	return runtime.GOOS != "windows" && GetEffectiveUID() == 0
}

// GetCurrentUser returns information about the current user
func GetCurrentUser() (username string, uid string, err error) {
	if runtime.GOOS == "windows" {
		return "", "", nil
	}

	u, err := user.Current()
	if err != nil {
		return "", "", err
	}
	return u.Username, u.Uid, nil
}

// GetHomeDirectory returns the home directory of the current user
func GetHomeDirectory() string {
	home, err := os.UserHomeDir()
	if err != nil {
		return ""
	}
	return home
}

// ParseUID parses a string to UID
func ParseUID(uidStr string) (int, error) {
	return strconv.Atoi(uidStr)
}
