package version

import (
	"bufio"
	"os"
	"strings"
)

func GetCurrentBranch() string {
	branch, err := os.ReadFile(BranchPath)
	if err != nil {
		return "stable"
	}
	return string(branch)
}

func DetermineCurrentVersion() string {
	file, err := os.Open("/etc/os-release")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	var lastLine string
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		lastLine = scanner.Text()
	}
	if err := scanner.Err(); err != nil {
		panic(err)
	}

	parts := strings.SplitN(lastLine, "=", 2)
	if len(parts) != 2 {
		panic("invalid format")
	}
	value := parts[1]

	currentVersion := strings.Trim(value, "\"")
	return currentVersion
}
