package python

import (
	"fmt"
	"path/filepath"

	"zlh-agent/internal/provision"
	"zlh-agent/internal/provision/devcontainer"
	"zlh-agent/internal/state"
)

/*
   Install installs the Python dev container runtime.

   Execution model:
   - Uses local, versioned install scripts from the agent repo
   - Scripts are responsible for fetching artifacts if needed

   IMPORTANT:
   - This function ONLY installs
   - No verification here
*/
func Install(cfg state.Config) error {

	// Idempotency guard
	if devcontainer.IsProvisioned() {
		return nil
	}

	scriptPath := filepath.Join(
		provision.ScriptsRoot,
		"devcontainer",
		"python",
		"install.sh",
	)

	if err := provision.RunScript(scriptPath); err != nil {
		return fmt.Errorf("python devcontainer install failed: %w", err)
	}

	if err := devcontainer.WriteReadyMarker("python"); err != nil {
		return fmt.Errorf("failed to write devcontainer ready marker: %w", err)
	}

	return nil
}
