package message

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestBuildAgentUnreadSummary(t *testing.T) {
	t.Parallel()

	summary := BuildAgentUnreadSummary([]AgentUnreadThread{
		{ChannelType: "channel", ChannelName: "all", UnreadCount: 2},
		{ChannelType: "dm", ChannelName: "owner01", UnreadCount: 1},
		{ChannelType: "thread", ChannelName: "thread-abcd1234", ParentChannelType: "channel", ParentChannelName: "all", UnreadCount: 3},
		{ChannelType: "thread", ChannelName: "thread-ef012345", ParentChannelType: "dm", ParentChannelName: "owner01", UnreadCount: 4},
		{ChannelType: "channel", ChannelName: "ignored", UnreadCount: 0},
	})

	require.Equal(t, map[string]int{
		"#all":                 2,
		"DM:@owner01":          1,
		"#all:abcd1234":        3,
		"DM:@owner01:ef012345": 4,
	}, summary)
}

func TestBuildAgentUnreadSummaryReturnsNilWhenEmpty(t *testing.T) {
	t.Parallel()

	require.Nil(t, BuildAgentUnreadSummary(nil))
	require.Nil(t, BuildAgentUnreadSummary([]AgentUnreadThread{
		{ChannelType: "channel", ChannelName: "all", UnreadCount: 0},
		{ChannelType: "thread", ChannelName: "thread-abcd1234", ParentChannelType: "channel", ParentChannelName: "", UnreadCount: 2},
	}))
}
