package builder

import (
	"strings"
	"testing"
)

func TestGenerateUninstallScriptContainsPersistenceKey(t *testing.T) {
	req := &BuildRequest{
		WorkerName:  "office-pc",
		ProcessName: "RuntimeHelper",
		StealthMode: false,
		InstallBase: "localappdata",
	}
	script := generateUninstallScript("abc12345-uuid", req)
	if !strings.Contains(script, "CryptoMiner-office-pc") {
		t.Fatalf("expected normal persistence key in script, got: %s", script)
	}
	if !strings.Contains(script, "RuntimeHelper") {
		t.Fatal("expected process name in script")
	}
}

func TestGenerateUninstallScriptStealthKey(t *testing.T) {
	req := &BuildRequest{
		WorkerName:  "office-pc",
		ProcessName: "RuntimeHelper",
		StealthMode: true,
	}
	script := generateUninstallScript("abc12345-uuid", req)
	if !strings.Contains(script, "RuntimeHelper") {
		t.Fatalf("expected stealth persistence key to match process name")
	}
}

func TestGenerateUninstallScriptInstallPathTokens(t *testing.T) {
	req := &BuildRequest{
		WorkerName:          "office-pc",
		ProcessName:         "RuntimeHelper",
		InstallBase:         "localappdata",
		InstallRelativePath: "CryptoMiner/{worker}-{build_short}",
	}
	script := generateUninstallScript("abc12345-uuid", req)
	if !strings.Contains(script, "office-pc-abc12345") {
		t.Fatalf("expected expanded install relative path in script, got fragment missing")
	}
	if !strings.Contains(script, "$env:LOCALAPPDATA") {
		t.Fatal("expected LOCALAPPDATA base in script")
	}
}
