package api

import "testing"

func TestAgentConfigPoolHostOrDefault(t *testing.T) {
	t.Run("empty uses fallback", func(t *testing.T) {
		cfg := AgentForgeConfig{}
		if got := cfg.poolHostOrDefault("fallback.host"); got != "fallback.host" {
			t.Fatalf("got %q, want fallback.host", got)
		}
	})
	t.Run("explicit host wins", func(t *testing.T) {
		cfg := AgentForgeConfig{PoolHost: "pool.example.com"}
		if got := cfg.poolHostOrDefault("fallback"); got != "pool.example.com" {
			t.Fatalf("got %q, want pool.example.com", got)
		}
	})
}

func TestAgentConfigPoolPortOrDefault(t *testing.T) {
	t.Run("zero uses fallback", func(t *testing.T) {
		cfg := AgentForgeConfig{}
		if got := cfg.poolPortOrDefault(3333); got != 3333 {
			t.Fatalf("got %d, want 3333", got)
		}
	})
	t.Run("negative uses fallback", func(t *testing.T) {
		cfg := AgentForgeConfig{PoolPort: -1}
		if got := cfg.poolPortOrDefault(3333); got != 3333 {
			t.Fatalf("got %d, want 3333", got)
		}
	})
	t.Run("explicit port wins", func(t *testing.T) {
		cfg := AgentForgeConfig{PoolPort: 443}
		if got := cfg.poolPortOrDefault(3333); got != 443 {
			t.Fatalf("got %d, want 443", got)
		}
	})
}
