package mysql

import (
	"testing"

	"hyapp/services/wallet-service/internal/domain/ledger"
)

func TestBalanceChangedEventPersistsPrivateNoticeSuppressionSnapshot(t *testing.T) {
	event := balanceChangedEvent(
		"tx-robot-1",
		"cmd-robot-1",
		100001,
		// COIN 刻意不依赖 ROBOT_COIN 兼容分支，证明强类型 giftMetadata.RobotGift 本身能固化决策。
		ledger.AssetCoin,
		-10,
		0,
		90,
		0,
		2,
		giftMetadata{RobotGift: true},
		1710000000000,
		bizTypeRobotGiftDebit,
	)
	payload, ok := event.Payload.(map[string]any)
	if !ok {
		t.Fatalf("payload type = %T, want map[string]any", event.Payload)
	}
	if suppressed, ok := payload["suppress_private_notice"].(bool); !ok || !suppressed {
		t.Fatalf("suppress_private_notice = %#v, want true", payload["suppress_private_notice"])
	}
	legacyRobotAsset := balanceChangedEvent(
		"tx-robot-asset-1",
		"cmd-robot-asset-1",
		100001,
		ledger.AssetRobotCoin,
		-10,
		0,
		90,
		0,
		2,
		struct{}{},
		1710000000000,
		bizTypeRobotGiftDebit,
	)
	legacyRobotPayload := legacyRobotAsset.Payload.(map[string]any)
	if suppressed, ok := legacyRobotPayload["suppress_private_notice"].(bool); !ok || !suppressed {
		t.Fatalf("ROBOT_COIN compatibility suppression = %#v, want true", legacyRobotPayload["suppress_private_notice"])
	}

	human := balanceChangedEvent(
		"tx-human-1",
		"cmd-human-1",
		100002,
		ledger.AssetCoin,
		-10,
		0,
		90,
		0,
		2,
		giftMetadata{},
		1710000000000,
		bizTypeGiftDebit,
	)
	humanPayload := human.Payload.(map[string]any)
	if _, exists := humanPayload["suppress_private_notice"]; exists {
		t.Fatalf("human wallet event must not persist suppression control: %#v", humanPayload)
	}
}
