package ai

import "time"

// MobRegistry holds all mob definitions.
type MobRegistry struct {
	defs map[uint32]*MobDef
}

// NewMobRegistry creates a registry with default mob definitions.
func NewMobRegistry() *MobRegistry {
	r := &MobRegistry{defs: make(map[uint32]*MobDef)}
	r.registerDefaults()
	return r
}

// Get returns a mob definition by ID.
func (r *MobRegistry) Get(id uint32) *MobDef {
	return r.defs[id]
}

func (r *MobRegistry) registerDefaults() {
	r.defs[1] = &MobDef{
		ID:          1,
		Name:        "Goblin",
		Level:       1,
		HP:          60,
		MP:          0,
		Str:         8,
		Dex:         6,
		Int:         3,
		MoveSpeed:   4.0,
		AggroRange:  10.0,
		AttackRange: 2.5,
		AttackSkill: 1, // basic attack
		LeashRange:  30.0,
		ExpReward:   20,
		LootTable: []LootEntry{
			{ItemID: 101, Quantity: 1, Chance: 0.5},
		},
	}

	r.defs[2] = &MobDef{
		ID:          2,
		Name:        "Wolf",
		Level:       2,
		HP:          80,
		MP:          0,
		Str:         12,
		Dex:         10,
		Int:         2,
		MoveSpeed:   6.0,
		AggroRange:  12.0,
		AttackRange: 2.0,
		AttackSkill: 1,
		LeashRange:  35.0,
		ExpReward:   35,
		LootTable: []LootEntry{
			{ItemID: 102, Quantity: 1, Chance: 0.4},
			{ItemID: 103, Quantity: 1, Chance: 0.1},
		},
	}

	r.defs[3] = &MobDef{
		ID:          3,
		Name:        "Forest Troll",
		Level:       5,
		HP:          200,
		MP:          30,
		Str:         25,
		Dex:         8,
		Int:         5,
		MoveSpeed:   3.0,
		AggroRange:  8.0,
		AttackRange: 3.0,
		AttackSkill: 1,
		LeashRange:  25.0,
		ExpReward:   80,
		LootTable: []LootEntry{
			{ItemID: 104, Quantity: 1, Chance: 0.6},
			{ItemID: 105, Quantity: 1, Chance: 0.15},
		},
	}

	r.defs[4] = &MobDef{
		ID:          4,
		Name:        "Fire Elemental",
		Level:       8,
		HP:          350,
		MP:          100,
		Str:         15,
		Dex:         12,
		Int:         30,
		MoveSpeed:   3.5,
		AggroRange:  15.0,
		AttackRange: 10.0,
		AttackSkill: 2, // fireball
		LeashRange:  40.0,
		ExpReward:   150,
		LootTable: []LootEntry{
			{ItemID: 106, Quantity: 1, Chance: 0.3},
			{ItemID: 107, Quantity: 1, Chance: 0.05},
		},
	}

	r.defs[5] = &MobDef{
		ID:          5,
		Name:        "Dragon Whelp",
		Level:       12,
		HP:          800,
		MP:          200,
		Str:         35,
		Dex:         20,
		Int:         25,
		MoveSpeed:   5.0,
		AggroRange:  20.0,
		AttackRange: 4.0,
		AttackSkill: 2,
		LeashRange:  50.0,
		ExpReward:   350,
		LootTable: []LootEntry{
			{ItemID: 108, Quantity: 1, Chance: 0.4},
			{ItemID: 109, Quantity: 1, Chance: 0.02},
		},
	}

	// Adjust respawn-related values (these go in SpawnPoints, not MobDef, but
	// set sensible AttackSkill cooldowns via the existing combat skill system)
	_ = time.Second // reference for documentation
}
