package profile

import (
	"fmt"
	"strings"
)

type BuildInput struct {
	PrivateKey       string
	Address          string
	DNSServers       []string
	ServerPublicKey  string
	ServerEndpoint   string
	AllowedIPs       []string
	PersistentKeepal int
}

func BuildWireGuardConfig(input BuildInput) string {
	var b strings.Builder
	b.WriteString("[Interface]\n")
	b.WriteString(fmt.Sprintf("PrivateKey = %s\n", input.PrivateKey))
	b.WriteString(fmt.Sprintf("Address = %s\n", input.Address))
	if len(input.DNSServers) > 0 {
		b.WriteString(fmt.Sprintf("DNS = %s\n", strings.Join(input.DNSServers, ", ")))
	}

	b.WriteString("\n[Peer]\n")
	b.WriteString(fmt.Sprintf("PublicKey = %s\n", input.ServerPublicKey))
	b.WriteString(fmt.Sprintf("Endpoint = %s\n", input.ServerEndpoint))
	b.WriteString(fmt.Sprintf("AllowedIPs = %s\n", strings.Join(input.AllowedIPs, ", ")))
	b.WriteString(fmt.Sprintf("PersistentKeepalive = %d\n", input.PersistentKeepal))
	return b.String()
}
