package goenv

import (
	"fmt"

	"zlh-agent/internal/provision/executil"
	"zlh-agent/internal/provision/markers"
	"zlh-agent/internal/state"
)

func Install(cfg state.Config) error {
	const marker = "devcontainer-go"

	if markers.IsPresent(marker) {
		return nil
	}

	if err := executil.RunEmbeddedScript(
		"devcontainer/go/install.sh",
		"RUNTIME=go",
		"ARCHIVE_EXT=tar.gz",
		"RUNTIME_VERSION="+cfg.Version,
	); err != nil {
		return fmt.Errorf("go devcontainer install failed: %w", err)
	}

	return markers.Write(marker)
}
