package model

import (
	"strings"
	"testing"
)

func TestRoadsideSlugsWellFormed(t *testing.T) {
	if len(RoadsideSlugs) == 0 {
		t.Fatal("RoadsideSlugs empty")
	}
	for _, s := range RoadsideSlugs {
		if strings.Contains(s, ".") {
			t.Fatalf("roadside slug must not contain dot: %q", s)
		}
		if RoadsidePhraseKey(s) != "roadside."+s {
			t.Fatalf("RoadsidePhraseKey(%q)=%q want roadside.%s", s, RoadsidePhraseKey(s), s)
		}
	}
}

func TestTownVisitPhraseKeyUsesSlugs(t *testing.T) {
	k := TownVisitPhraseKey("merchant", 4)
	if k != "town_visit.merchant.bell_traveler_pack" {
		t.Fatalf("got %q", k)
	}
	k2 := TownVisitPhraseKey("unknown_npc", 0)
	if k2 != "town_visit.generic.town_noise_blanket" {
		t.Fatalf("unknown type should use generic slugs, got %q", k2)
	}
}

func TestTownVisitRandomPhraseKeyNonEmpty(t *testing.T) {
	for i := 0; i < 20; i++ {
		k := TownVisitRandomPhraseKey("bounty_hunter")
		if k == "" || len(k) < len("town_visit.bounty_hunter.") {
			t.Fatalf("expected bounty_hunter phrase key, got %q", k)
		}
		k = TownVisitRandomPhraseKey("merchant")
		if k == "" || len(k) < len("town_visit.merchant.") {
			t.Fatalf("unexpected key %q", k)
		}
	}
}
