-- =============================================================================
-- Item Registry Lua API Examples
-- =============================================================================
-- This file demonstrates how to register item definitions using the
-- ecs.items API. Run this from data.lua or any other Lua entry point
-- to populate the global item registry.
--
-- The ItemRegistry is a global singleton. Items defined here are
-- immediately available for use in inventories, containers, and quests.
-- =============================================================================

-- =============================================================================
-- Registering Items
-- =============================================================================

-- Consumables
ecs.items.register("potion_health", {
    itemName = "Health Potion",
    itemType = "consumable",
    maxStackSize = 10,
    weight = 0.5,
    value = 25,
    useActionName = "drink_potion",
    unique = false
})

ecs.items.register("potion_stamina", {
    itemName = "Stamina Potion",
    itemType = "consumable",
    maxStackSize = 10,
    weight = 0.5,
    value = 20,
    useActionName = "drink_potion",
    unique = false
})

-- Weapons
ecs.items.register("sword_iron", {
    itemName = "Iron Sword",
    itemType = "weapon",
    maxStackSize = 1,
    weight = 3.5,
    value = 100,
    useActionName = "equip_weapon",
    unique = false
})

ecs.items.register("bow_wood", {
    itemName = "Wooden Bow",
    itemType = "weapon",
    maxStackSize = 1,
    weight = 2.0,
    value = 75,
    useActionName = "equip_weapon",
    unique = false
})

-- Ammo
ecs.items.register("arrow", {
    itemName = "Arrow",
    itemType = "ammo",
    maxStackSize = 99,
    weight = 0.1,
    value = 2,
    useActionName = "",
    unique = false
})

-- Unique quest item
ecs.items.register("amulet_legendary", {
    itemName = "Amulet of the Ancients",
    itemType = "quest",
    maxStackSize = 1,
    weight = 0.2,
    value = 5000,
    useActionName = "inspect_amulet",
    unique = true
})

-- Currency
ecs.items.register("gold_coin", {
    itemName = "Gold Coin",
    itemType = "currency",
    maxStackSize = 999,
    weight = 0.01,
    value = 1,
    useActionName = "",
    unique = false
})

-- =============================================================================
-- Querying the Item Registry
-- =============================================================================

-- Find an item by ID:
local potion = ecs.items.find("potion_health")
if potion then
    print("Found item: " .. potion.itemName .. " (" .. potion.itemType .. ")")
    print("  Max stack: " .. potion.maxStackSize)
    print("  Weight: " .. potion.weight)
    print("  Value: " .. potion.value)
    print("  Unique: " .. tostring(potion.unique))
end

-- Check if an item is unique:
if ecs.items.is_unique("amulet_legendary") then
    print("Amulet of the Ancients is a unique item")
end

-- List all registered items:
print("Registered items:")
local all_items = ecs.items.list()
for _, id in ipairs(all_items) do
    local def = ecs.items.find(id)
    print("  " .. id .. " - " .. def.itemName .. " (" .. def.itemType .. ")")
end

-- =============================================================================
-- Item Definition Fields Reference
-- =============================================================================
--
-- ecs.items.register(itemId, definition)
--   itemId     - string, unique identifier for the item
--   definition - table with fields:
--     itemName      - string, display name
--     itemType      - string, category ("consumable", "weapon", "ammo",
--                     "quest", "currency", "material", "armor", etc.)
--     maxStackSize  - integer, maximum items per inventory slot
--     weight        - number, weight per item
--     value         - integer, base value in gold
--     useActionName - string, GOAP action name when used (empty = no action)
--     unique        - boolean, true if only one instance allowed per character
--
-- ecs.items.find(itemId) -> table or nil
--   Returns the item definition table with all fields above.
--
-- ecs.items.list() -> table of item ID strings
--   Returns all registered item IDs.
--
-- ecs.items.is_unique(itemId) -> boolean
--   Returns true if the item is marked as unique.
-- =============================================================================

print("Item registry examples completed successfully!")
