package message

import (
	"testing"

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

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

	normalized := NormalizeReplyThreadParticipantIDs([]string{" agt-2 ", "", "usr-1", "agt-2", "agt-1"})
	require.Equal(t, []string{"agt-1", "agt-2", "usr-1"}, normalized)
}

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

	raw, err := MarshalReplyThreadParticipantIDs([]string{" agt-2 ", "usr-1", "agt-2", "agt-1"})
	require.NoError(t, err)
	require.JSONEq(t, `["agt-1","agt-2","usr-1"]`, string(raw))
}

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

	merged := MergeReplyThreadParticipantIDs([]string{"usr-1", "agt-2"}, []string{"agt-1", "agt-2", "usr-1"})
	require.Equal(t, []string{"agt-1", "agt-2", "usr-1"}, merged)
}
