class_name Item

# Enum Types
enum Type {
  NULL,
  
  MEDICINE,
  KEY_ITEM,
}

enum Id {
  NULL,
  POTION,
}

# Main dictionary holding all item data
static var ITEM_DATA:Array = []

# Class definition
static func itemDefine(params:Dictionary) -> Dictionary:
  assert(params.has('id'))
  assert(params.has('handle'))
  assert(params.has('type'))

  var obj:Dictionary = {}
  ITEM_DATA.insert(params['id'], obj)

  obj['id'] = params['id']
  obj['handle'] = params['handle']
  obj['type'] = params['type']

  return obj

# Item Data
static var ITEM_NULL = itemDefine({
  'id': Id.NULL,
  'handle': "unknown",
  'type': Type.NULL
})

static var POTION = itemDefine({
  'id': Id.POTION,
  'handle': "potion",
  'type': Type.MEDICINE
})

# Item Accessors
static func getItemDef(item:Id) -> Dictionary:
  if ITEM_DATA.size() <= item || item < 0:
    return ITEM_NULL
  return ITEM_DATA[item]

static func getType(item:Id) -> Type:
  return getItemDef(item).type

static func getItemHandle(item:Id) -> String:
  return getItemDef(item).handle

static func getItemName(item:Id) -> String:
  var handle = Item.getItemHandle(item)
  return (handle + "_name").to_upper()
