package im

import (
	"context"
	"testing"

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

func TestTaskLifecycleProtectedRecipientRefreshIsExact(t *testing.T) {
	ctx := WithTaskLifecycleProtectedScopes(
		context.Background(),
		"wsp_protected",
		[]string{"tsk_protected"},
	)
	taskRecipients := []scopeEventRecipient{{
		MemberID:  "mem_reader",
		ScopeKind: "task",
	}}

	require.True(t, taskLifecycleProtectedRecipientRefresh(
		ctx,
		"wsp_protected",
		"tsk_protected",
		taskRecipients,
	))
	require.False(t, taskLifecycleProtectedRecipientRefresh(
		ctx,
		"wsp_protected",
		"tsk_other",
		taskRecipients,
	))
	require.False(t, taskLifecycleProtectedRecipientRefresh(
		ctx,
		"wsp_other",
		"tsk_protected",
		taskRecipients,
	))
	require.False(t, taskLifecycleProtectedRecipientRefresh(
		ctx,
		"wsp_protected",
		"tsk_protected",
		[]scopeEventRecipient{{
			MemberID:  "mem_reader",
			ScopeKind: "channel",
		}},
	))
	require.False(t, taskLifecycleProtectedRecipientRefresh(
		ctx,
		"wsp_protected",
		"tsk_protected",
		[]scopeEventRecipient{
			{MemberID: "mem_task", ScopeKind: "task"},
			{MemberID: "mem_channel", ScopeKind: "channel"},
		},
	))
}
