package lotteryengine

import "testing"

func TestNormalizeCandidatesKeepsPositiveWeights(t *testing.T) {
	candidates, err := NormalizeCandidates([]Candidate{
		{ID: "zero", Weight: 0, PrizeKind: PrizeKindCoin, RTPValueCoins: 10},
		{ID: "coin", Weight: 7, PrizeKind: PrizeKindCoin, RTPValueCoins: 20},
	})
	if err != nil {
		t.Fatalf("NormalizeCandidates failed: %v", err)
	}
	if len(candidates) != 1 || candidates[0].ID != "coin" || candidates[0].Weight != 7 || candidates[0].RTPValueCoins != 20 {
		t.Fatalf("unexpected normalized candidates: %#v", candidates)
	}
}

func TestNormalizeCandidatesFallsBackToEqualWeight(t *testing.T) {
	candidates, err := NormalizeCandidates([]Candidate{
		{ID: "a", PrizeKind: PrizeKindCoin},
		{ID: "b", PrizeKind: PrizeKindGift},
	})
	if err != nil {
		t.Fatalf("NormalizeCandidates failed: %v", err)
	}
	if len(candidates) != 2 || candidates[0].Weight != 1 || candidates[1].Weight != 1 {
		t.Fatalf("zero-weight candidates should become equal-weight candidates: %#v", candidates)
	}
}

func TestNormalizeRTPValueCoinsForcesPropsAndDressToZero(t *testing.T) {
	tests := []string{PrizeKindProp, PrizeKindDress, "item", "decoration", "resource", "costume"}
	for _, kind := range tests {
		if got := NormalizeRTPValueCoins(kind, 999_999); got != 0 {
			t.Fatalf("kind %s should not count into RTP, got %d", kind, got)
		}
	}
	if got := NormalizeRTPValueCoins(PrizeKindCoin, 500); got != 500 {
		t.Fatalf("coin should keep rtp value, got %d", got)
	}
	if got := NormalizeRTPValueCoins(PrizeKindGift, -1); got != 0 {
		t.Fatalf("negative gift rtp value should clamp to zero, got %d", got)
	}
}
