package node

import (
	"fmt"
	"os"
	"os/exec"

	"zlh-agent/internal/state"
)

const (
	nodeBin = "/opt/zlh/runtimes/node/bin/node"
	npmBin  = "/opt/zlh/runtimes/node/bin/npm"
)

func Verify(cfg state.Config) error {

	// Node must exist
	if _, err := os.Stat(nodeBin); err != nil {
		return fmt.Errorf("node binary missing at %s", nodeBin)
	}

	// Node must execute
	if err := exec.Command(nodeBin, "-v").Run(); err != nil {
		return fmt.Errorf("node runtime not executable: %w", err)
	}

	// npm must exist (installation completeness)
	if _, err := os.Stat(npmBin); err != nil {
		return fmt.Errorf("npm missing at %s", npmBin)
	}

	// Do NOT execute npm here — it is PATH-dependent by design
	return nil
}
