package dispatcher

import "testing"

func TestAgentOverrides_GetSet(t *testing.T) {
	o := NewAgentOverrides()

	if got := o.Get("ch1", "conv1"); got != "" {
		t.Errorf("Get() = %q, want empty", got)
	}

	o.Set("ch1", "conv1", "agent-a")
	if got := o.Get("ch1", "conv1"); got != "agent-a" {
		t.Errorf("Get() = %q, want %q", got, "agent-a")
	}
}

func TestAgentOverrides_DifferentConversations(t *testing.T) {
	o := NewAgentOverrides()
	o.Set("ch1", "conv1", "agent-a")
	o.Set("ch1", "conv2", "agent-b")
	o.Set("ch2", "conv1", "agent-c")

	if got := o.Get("ch1", "conv1"); got != "agent-a" {
		t.Errorf("ch1:conv1 = %q, want %q", got, "agent-a")
	}
	if got := o.Get("ch1", "conv2"); got != "agent-b" {
		t.Errorf("ch1:conv2 = %q, want %q", got, "agent-b")
	}
	if got := o.Get("ch2", "conv1"); got != "agent-c" {
		t.Errorf("ch2:conv1 = %q, want %q", got, "agent-c")
	}
}

func TestAgentOverrides_Overwrite(t *testing.T) {
	o := NewAgentOverrides()
	o.Set("ch1", "conv1", "agent-a")
	o.Set("ch1", "conv1", "agent-b")

	if got := o.Get("ch1", "conv1"); got != "agent-b" {
		t.Errorf("Get() = %q, want %q after overwrite", got, "agent-b")
	}
}
