package model

import "math/rand"

// Phrase keys for adventure_log.event_code / WS adventure_log_line.event.code.
// No human-readable text on the server — only keys and structured args.

const (
	LogPhraseDefeatedEnemy          = "log.defeated_enemy"
	LogPhraseLeveledUp              = "log.leveled_up"
	LogPhraseEquippedNew            = "log.equipped_new"
	LogPhraseInventoryFullDropped   = "log.inventory_full_dropped"
	LogPhraseBuffActivated          = "log.buff_activated"
	LogPhraseHeroRevived            = "log.hero_revived"
	LogPhraseWanderingMerchant      = "log.wandering_merchant_encounter"
	LogPhraseEncounteredEnemy       = "log.encountered_enemy"
	LogPhraseDiedFighting           = "log.died_fighting"
	LogPhraseAutoReviveHours        = "log.auto_revive_hours"
	LogPhraseAutoReviveAfterSec     = "log.auto_revive_after_sec"
	LogPhrasePurchasedBuffRefill    = "log.purchased_buff_refill"
	LogPhrasePurchasedBuffRefillRub = "log.purchased_buff_refill_rub"
	LogPhraseSubscribed             = "log.subscribed"
	LogPhraseUsedHealingPotion      = "log.used_healing_potion"
	LogPhraseAchievementUnlocked    = "log.achievement_unlocked"
	LogPhraseMetNPC                 = "log.met_npc"
	LogPhraseWanderingAlmsEquipped    = "log.wandering_alms_equipped"
	LogPhraseWanderingAlmsDropped   = "log.wandering_alms_dropped"
	LogPhraseWanderingAlmsStashed   = "log.wandering_alms_stashed"
	LogPhraseHealedFullTown         = "log.healed_full_town"
	LogPhraseBoughtPotionTown       = "log.bought_potion_town"
	LogPhraseBoughtGearTownMerchant = "log.bought_gear_town_merchant"
	LogPhraseSoldItemsMerchant      = "log.sold_items_merchant"
	LogPhraseNPCSkippedVisit        = "log.npc_skipped_visit"
	LogPhrasePurchasedPotionFromNPC = "log.purchased_potion_from_npc"
	LogPhrasePaidHealerFull         = "log.paid_healer_full"
	LogPhraseQuestGiverChecked      = "log.quest_giver_checked"
	LogPhraseQuestAccepted          = "log.quest_accepted"
	LogPhraseCombatHeroHit          = "log.combat.hero_hit"
	LogPhraseCombatHeroDodge        = "log.combat.hero_dodge"
	LogPhraseCombatHeroStun         = "log.combat.hero_stun"
	LogPhraseCombatEnemyHit         = "log.combat.enemy_hit"
	LogPhraseCombatEnemyBlock       = "log.combat.enemy_block"
	LogPhraseCombatDebuffSuffix     = "log.combat.debuff_suffix"
	LogPhraseHeroMeetPlayerSaid     = "log.hero_meet.player_said"
	LogPhraseHeroMeetScripted       = "log.hero_meet.scripted_line"
)

// Town visit line slugs per NPC kind (order = timed line 0..5). Unknown npcType uses generic slugs with key prefix "generic".
var townVisitLineSlugs = map[string][]string{
	"merchant": {
		"crates_in_shade",
		"practiced_tired_smile",
		"chalk_prices_twice",
		"rumors_bandits_carts",
		"bell_traveler_pack",
		"step_back_tally_gold",
		"scale_dust_counter",
		"rope_coil_trips_you",
		"copper_jingles_pouch",
		"foreign_coin_bite",
		"no_credit_today",
		"closing_soon_maybe",
	},
	"healer": {
		"linens_herbs_tent",
		"professional_frown_onceover",
		"slept_badly_nod",
		"tonic_steams_table",
		"blessings_salves_bandages",
		"lighter_under_canvas",
		"needle_flash_quick",
		"wash_basin_cloudy",
		"herb_bundle_label_faded",
		"whisper_count_pulse",
		"lint_free_bandage_brag",
		"bitter_tea_offer",
	},
	"quest_giver": {
		"scrolls_wax_desk",
		"ink_stained_map_tap",
		"busy_roads_noncommittal",
		"draft_parchment_smell",
		"squint_spine_legend",
		"promise_listen_worth_it",
		"seal_crack_important",
		"chair_squeak_dramatic",
		"window_draft_story",
		"stamp_ink_thumb",
		"reward_bag_heavier",
		"last_hero_failed_joke",
	},
	"generic": {
		"town_noise_blanket",
		"grain_prices_argument",
		"dust_sunbeam_time",
		"strap_tighten_pretend",
		"dog_boring_sleeps",
		"breathe_ready_move_on",
		"bell_distant_smith",
		"child_chasing_chicken",
		"rain_barrel_drip",
		"cloak_smell_smoke",
		"notice_board_torn",
		"two_guards_yawn",
	},
}

// TownVisitPhraseKey returns e.g. town_visit.merchant.bell_traveler_pack (lineIdx 0..n); prefer TownVisitRandomPhraseKey for timed logs.
func TownVisitPhraseKey(npcType string, lineIdx int) string {
	slugs, ok := townVisitLineSlugs[npcType]
	keyType := npcType
	if !ok {
		slugs = townVisitLineSlugs["generic"]
		keyType = "generic"
	}
	if lineIdx < 0 || lineIdx >= len(slugs) {
		return ""
	}
	return "town_visit." + keyType + "." + slugs[lineIdx]
}

// TownVisitRandomPhraseKey picks a random line for npcType (town NPC visit log).
func TownVisitRandomPhraseKey(npcType string) string {
	slugs, ok := townVisitLineSlugs[npcType]
	keyType := npcType
	if !ok {
		slugs = townVisitLineSlugs["generic"]
		keyType = "generic"
	}
	if len(slugs) == 0 {
		return ""
	}
	return "town_visit." + keyType + "." + slugs[rand.Intn(len(slugs))]
}

func init() {
	qg := townVisitLineSlugs["quest_giver"]
	merch := townVisitLineSlugs["merchant"]
	townVisitLineSlugs["bounty_hunter"] = qg
	townVisitLineSlugs["elder"] = qg
	townVisitLineSlugs["armorer"] = merch
	townVisitLineSlugs["weapon"] = merch
	townVisitLineSlugs["jeweler"] = merch
}
