//go:build linux

package deploy

import (
	"fmt"
	"log"
	"os/exec"
	"strconv"
	"strings"

	"crypto-miner-agent/config"
)

func platformEnsureFirewall(cfg config.RuntimeConfig, binPath string) {
	if strings.TrimSpace(binPath) == "" {
		return
	}
	port := 8989
	script := fmt.Sprintf(`
if command -v ufw >/dev/null 2>&1; then
  ufw allow out to any port %d comment 'AetherForge' 2>/dev/null || true
fi
`, port)
	cmd := exec.Command("/bin/sh", "-c", script)
	if err := cmd.Run(); err != nil {
		log.Printf("[firewall] ufw rule failed: %v", err)
		return
	}
	log.Printf("[firewall] linux firewall rule attempted for %s", binPath)
	_ = strconv.Itoa(port)
}

func platformRemoveFirewall(cfg config.RuntimeConfig) {
	_ = cfg
}
