package java

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-java"

	if markers.IsPresent(marker) {
		return nil
	}

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

	return markers.Write(marker)
}
