package webrtc

import (
	"testing"
)

func TestConfig_Defaults(t *testing.T) {
	c := DefaultConfig()
	if !c.Enabled {
		t.Error("default Enabled should be true")
	}
	if c.WHEPListen != ":8787" {
		t.Errorf("default WHEPListen = %q, want :8787", c.WHEPListen)
	}
	if c.UDPPortRange.Low != 10000 || c.UDPPortRange.High != 10100 {
		t.Errorf("default UDPPortRange = %v, want 10000-10100", c.UDPPortRange)
	}
	if c.MaxPeersTotal != 32 {
		t.Errorf("default MaxPeersTotal = %d, want 32", c.MaxPeersTotal)
	}
	if len(c.ICEServers) == 0 {
		t.Error("default ICEServers should have at least one STUN entry")
	}
}

func TestConfig_Validate(t *testing.T) {
	tests := []struct {
		name    string
		mutate  func(*Config)
		wantErr bool
	}{
		{"defaults are valid", func(c *Config) {}, false},
		{"empty listen", func(c *Config) { c.WHEPListen = "" }, true},
		{"inverted port range", func(c *Config) { c.UDPPortRange.Low = 20000; c.UDPPortRange.High = 10000 }, true},
		{"zero max peers", func(c *Config) { c.MaxPeersTotal = 0 }, true},
		{"negative max peers", func(c *Config) { c.MaxPeersTotal = -1 }, true},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			c := DefaultConfig()
			tt.mutate(&c)
			err := c.Validate()
			if (err != nil) != tt.wantErr {
				t.Errorf("Validate() err = %v, wantErr %v", err, tt.wantErr)
			}
		})
	}
}
