package mysql

import (
	"testing"

	resourcedomain "hyapp/services/wallet-service/internal/domain/resource"
)

func TestGiftTraySkinRequiresSVGAAnimation(t *testing.T) {
	base := resourcedomain.ResourceCommand{
		ResourceCode: "vip_gift_tray_5", ResourceType: resourcedomain.TypeGiftTraySkin,
		Name: "VIP5 Gift Tray", Status: resourcedomain.StatusActive,
		GrantStrategy: resourcedomain.GrantStrategyIncreaseQuantity,
		AnimationURL:  "https://cdn.example/vip-gift-tray.svga", MetadataJSON: `{"format":"svga"}`,
	}
	if err := validateResourceCommand(base); err != nil {
		t.Fatalf("valid SVGA gift tray should be accepted: %v", err)
	}
	base.MetadataJSON = `{"format":"mp4"}`
	if err := validateResourceCommand(base); err == nil {
		t.Fatal("gift tray must reject formats unsupported by the Fami SVGA player")
	}
}

func TestDecorativeResourceTypesAreEquipable(t *testing.T) {
	for _, resourceType := range []string{resourcedomain.TypeProfileCard, resourcedomain.TypeMicSeatIcon, resourcedomain.TypeMicSeatAnimation} {
		if !isEquipableResourceType(resourceType) {
			t.Fatalf("%s resources must use the equipment slot just like other profile decorations", resourceType)
		}
	}
}

func TestVIPTrialCardUsesInternalSingleSelectEquipmentSlot(t *testing.T) {
	if !isEquipableResourceType(resourcedomain.TypeVIPTrialCard) {
		t.Fatalf("vip_trial_card dedicated state machine must reuse the internal equipment slot")
	}
	if allowsMultipleEquippedResources(resourcedomain.TypeVIPTrialCard) {
		t.Fatalf("vip_trial_card equipment must keep exactly one current card")
	}
}

func TestGrantDefaultEquippedResourceTypes(t *testing.T) {
	for _, resourceType := range []string{resourcedomain.TypeBadge, resourcedomain.TypeMicSeatAnimation} {
		if !isAutoEquippedOnGrantResourceType(resourceType) {
			t.Fatalf("%s resources must auto equip inside resource grant transactions", resourceType)
		}
	}
	if isAutoEquippedOnGrantResourceType(resourcedomain.TypeAvatarFrame) {
		t.Fatalf("avatar_frame grants must not auto equip; level frames are display projection rewards, not user equipment changes")
	}
}
