package taskboard

import (
	"testing"

	"github.com/stretchr/testify/require"

	"github.com/tidbcloud/AgentTeam/internal/core/domain"
)

func TestTaskDiscussionPresentationProjectionFailsClosed(t *testing.T) {
	valid := domain.NewWorkflowRecoveryPresentation("wri_1", "wfx_1", "wfx_1", 1, 2)
	value, err := valid.MetadataValue()
	require.NoError(t, err)
	got := taskDiscussionPresentationFromMetadata(map[string]any{
		domain.MessagePresentationMetadataKey: value,
	})
	require.NotNil(t, got)
	require.Equal(t, domain.MessagePresentationKeyWorkflowRecovery, got.Key)

	unknownField := map[string]any{
		"version": 1,
		"key":     domain.MessagePresentationKeyWorkflowRecovery,
		"args": map[string]any{
			"runId": "wri_1", "stepId": "wfx_1", "effectId": "wfx_1", "attempt": 1, "totalAttempts": 2,
		},
		"extra": "must not cross the task DTO boundary",
	}
	require.Nil(t, taskDiscussionPresentationFromMetadata(map[string]any{
		domain.MessagePresentationMetadataKey: unknownField,
	}))
	require.Nil(t, taskDiscussionPresentationFromMetadata(map[string]any{
		domain.MessagePresentationMetadataKey: map[string]any{
			"version": 1, "key": "workflow.unknown", "args": map[string]any{},
		},
	}))
	require.Nil(t, taskDiscussionPresentationFromMetadata(map[string]any{
		"unrelated": map[string]any{"workflow": "private"},
	}))
}
