package model

type Slot string

const (
	SlotWeapon  Slot = "weapon"
	SlotArmor   Slot = "armor"
	SlotHelm    Slot = "helm"
	SlotTrinket Slot = "trinket"
)

type Item struct {
	ID        string   `json:"id"`
	Name      string   `json:"name"`
	Slot      Slot     `json:"slot"`
	Rarity    string   `json:"rarity"`
	Bonus     Stats    `json:"bonus"`
	Abilities []string `json:"abilities,omitempty"`
	Key       bool     `json:"key,omitempty"`
	Trait     string   `json:"trait,omitempty"`
	Value     int      `json:"value"`
}

var rarityWorth = map[string]int{"common": 4, "uncommon": 5, "rare": 7, "epic": 9, "legendary": 12}

func Price(it Item) int {
	b := it.Bonus
	worth := b.MaxHP/3 + b.Attack + b.Defense + b.Magic + (b.Speed+b.Crit)/2
	if it.Trait != "" {
		worth += 4
	}
	return max(1, worth*rarityWorth[it.Rarity])
}

type Gear map[Slot]*Item
