package track1

import (
	"testing"

	"github.com/explorer/backend/api/freshness"
	"github.com/stretchr/testify/require"
)

func TestResolveBridgeDeliveryModeLiveWithoutRelays(t *testing.T) {
	got := resolveBridgeDeliveryMode(false, nil, freshness.CompletenessComplete)
	require.Equal(t, "live", got.Kind)
	require.Nil(t, got.Reason)
}

func TestResolveBridgeDeliveryModeSnapshotWithRelays(t *testing.T) {
	got := resolveBridgeDeliveryMode(true, nil, freshness.CompletenessComplete)
	require.Equal(t, "snapshot", got.Kind)
	require.Equal(t, "live_homepage_stream_not_attached", got.Reason)
	require.Equal(t, "relay_monitoring_homepage_card_only", got.Scope)
}

func TestResolveBridgeDeliveryModeMixedWhenTransactionVisibilityStale(t *testing.T) {
	diagnostics := &freshness.Diagnostics{
		ActivityState: "fresh_head_stale_transaction_visibility",
	}
	got := resolveBridgeDeliveryMode(true, diagnostics, freshness.CompletenessPartial)
	require.Equal(t, "mixed", got.Kind)
	require.Equal(t, "relay_snapshot_only_source", got.Reason)
	require.Equal(t, "bridge_monitoring_and_homepage", got.Scope)
}

func TestResolveBridgeDeliveryModeMixedWhenQuietChain(t *testing.T) {
	diagnostics := &freshness.Diagnostics{
		ActivityState: "quiet_chain",
	}
	got := resolveBridgeDeliveryMode(false, diagnostics, freshness.CompletenessComplete)
	require.Equal(t, "live", got.Kind)
}

func TestIsStaleTransactionVisibility(t *testing.T) {
	require.True(t, isStaleTransactionVisibility(&freshness.Diagnostics{ActivityState: "fresh_head_stale_transaction_visibility"}))
	require.False(t, isStaleTransactionVisibility(&freshness.Diagnostics{ActivityState: "healthy"}))
}
