package mysql

import (
	"testing"

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

func TestRedPacketCreatedEventCarriesDisplayFacts(t *testing.T) {
	event := redPacketCreatedEvent("tx-red-packet-1", "cmd-red-packet-1", redPacketMetadata{
		PacketID:        "VRRP2026052712340001",
		PacketType:      ledger.RedPacketTypeDelayed,
		SenderUserID:    10001,
		RoomID:          "9001",
		RegionID:        310,
		RoomLocked:      true,
		OwnerUserID:     323411852102995968,
		TotalAmount:     15000,
		PacketCount:     5,
		RemainingAmount: 15000,
		RemainingCount:  5,
		Status:          ledger.RedPacketStatusWaitingOpen,
		OpenAtMS:        1_780_000_000_000,
		ExpiresAtMS:     1_780_086_400_000,
		CreatedAtMS:     1_779_999_700_000,
	}, 1_779_999_700_000)

	payload, ok := event.Payload.(map[string]any)
	if !ok {
		t.Fatalf("red packet created payload type mismatch: %T", event.Payload)
	}
	if payload["total_amount"] != int64(15000) || payload["packet_count"] != int32(5) || payload["remaining_count"] != int32(5) {
		t.Fatalf("red packet created payload must carry amount/count facts: %+v", payload)
	}
	if payload["status"] != ledger.RedPacketStatusWaitingOpen || payload["sender_user_id"] != int64(10001) {
		t.Fatalf("red packet created payload must carry status and sender facts: %+v", payload)
	}
	if payload["room_locked"] != true {
		t.Fatalf("red packet created payload must carry room lock snapshot: %+v", payload)
	}
	if payload["owner_user_id"] != int64(323411852102995968) {
		t.Fatalf("red packet created payload must carry owner snapshot: %+v", payload)
	}
}
