import logging

from BaseClasses import Item


def ItemFactory(items):
    ret = []
    singleton = False
    if isinstance(items, str):
        items = [items]
        singleton = True
    for item in items:
        if item in item_table:
            advancement, priority, type, code, index = item_table[item]
            ret.append(Item(item, advancement, priority, type, code, index))
        else:
            logging.getLogger('').warning('Unknown Item: %s', item)
            return None

    if singleton:
        return ret[0]
    return ret


# Format: Name: (Advancement, Priority, Type, ItemCode, Index)
item_table = {'Bow': (True, False, None, 0x0620, 0x31),
              'Hookshot': (True, False, None, 0x0120, 0x09),
              'Bomb Bag': (True, False, None, 0x0680, 0x34),
              'Lens of Truth': (True, False, None, 0x0140, 0x0A),
              'Fire Arrows': (True, False, None, 0x0B00, 0x58),
              'Ice Arrows': (True, False, None, 0x0B20, 0x59),
              'Light Arrows': (True, False, None, 0x0B40, 0x5A),
              'Ocarina of Time': (True, False, None, 0x0180, 0x0C),
              'Bottle': (True, False, None, None, None),
              'Bottle with Red Potion': (True, False, None, None, None),
              'Bottle with Gold Dust': (True, False, None, None, None),
              'Bottle with Milk': (True, False, None, None, None),
              'Bottle with Chateau Romani': (True, False, None, None, None),
              'Kokiri Sword': (True, False, None, 0x04E0, 0x27),
              'Hylian Shield': (False, False, None, 0x0540, 0x2A),
              'Mirror Shield': (True, False, None, 0x0560, 0x2B),
              'Goron Mask': (True, False, None, 0x0580, 0x2C),
              'Zora Mask': (True, False, None, 0x05A0, 0x2D),
              'Progressive Wallet': (True, False, None, 0x08C0, 0x46),
              'Piece of Heart': (False, False, None, 0x07C0, 0x3E),
              #'Recovery Heart': (False, True, None, 0x0900, 0x48),
              'Arrows (5)': (False, True, None, 0x0920, 0x49),
              'Arrows (10)': (False, True, None, 0x0940, 0x4A),
              'Arrows (30)': (False, True, None, 0x0960, 0x4B),
              'Bombs (5)': (False, True, None, 0x0020, 0x01),
              'Bombs (10)': (False, True, None, 0x0CC0, 0x66),
              'Bombs (20)': (False, True, None, 0x0CE0, 0x67),
              'Bombchus (5)': (False, False, None, 0x0D40, 0x6A),
              'Bombchus (10)': (False, False, None, 0x0060, 0x03),
              'Bombchus (20)': (False, False, None, 0x0D60, 0x6B),
              'Deku Nuts (5)': (False, True, None, 0x0040, 0x02),
              'Deku Nuts (10)': (False, True, None, 0x0C80, 0x64),
              'Rupee (1)': (False, False, None, 0x0980, 0x4C),
              'Rupees (5)': (False, False, None, 0x09A0, 0x4D),
              'Rupees (20)': (False, False, None, 0x09C0, 0x4E),
              'Rupees (50)': (False, False, None, 0x0AA0, 0x55),
              'Rupees (100)': (False, False, None, 0x0AC0, 0x56),
              'Ice Trap': (False, True, None, 0x0F80, 0x7C),
              'Magic Bean': (True, False, None, 0x02C0, 0x16),
              'Map': (False, False, 'Map', 0x0820, 0x41),
              'Compass': (False, False, 'Compass', 0x0800, 0x40),
              'Boss Key': (False, False, 'BossKey', 0x07E0, 0x3F),
              'Small Key': (False, False, 'SmallKey', 0x0840, 0x42),
              'Map (Woodfall Temple)': (False, False, 'Map', 0x0820, 0x41),
              'Compass (Woodfall Temple)': (False, False, 'Compass', 0x0800, 0x40),
              'Boss Key (Woodfall Temple)': (False, False, 'BossKey', 0x07E0, 0x3F),
              'Small Key (Woodfall Temple)': (False, False, 'SmallKey', 0x0840, 0x42),
              'Map (Snowhead Temple)': (False, False, 'Map', 0x0820, 0x41),
              'Compass (Snowhead Temple)': (False, False, 'Compass', 0x0800, 0x40),
              'Boss Key (Snowhead Temple)': (False, False, 'BossKey', 0x07E0, 0x3F),
              'Small Key (Snowhead Temple)': (False, False, 'SmallKey', 0x0840, 0x42),
              'Map (Water Temple)': (False, False, 'Map', 0x0820, 0x41),
              'Compass (Water Temple)': (False, False, 'Compass', 0x0800, 0x40),
              'Boss Key (Water Temple)': (False, False, 'BossKey', 0x07E0, 0x3F),
              'Small Key (Water Temple)': (False, False, 'SmallKey', 0x0840, 0x42),
              'Map (Shadow Temple)': (False, False, 'Map', 0x0820, 0x41),
              'Compass (Shadow Temple)': (False, False, 'Compass', 0x0800, 0x40),
              'Boss Key (Shadow Temple)': (False, False, 'BossKey', 0x07E0, 0x3F),
              'Small Key (Shadow Temple)': (False, False, 'SmallKey', 0x0840, 0x42),
              'Eponas Song': (True, False, 'Song', None, None),
              'Song of Time': (True, False, 'Song', None, None),
              'Song of Storms': (True, False, 'Song', None, None),
              'Magic Meter': (True, False, 'Event', None, None),
              'Epona': (True, False, 'Event', None, None),
              'Stray Fairy Pickup': (True, False, 'Event', None, None),
              'Odolwas Remains': (True, False, 'Event', None, None),
              'Triforce': (True, False, 'Event', None, None)}

item_data = {'Bow': [0x4C, 0x80, 0x17, 0xEE, 0x00, 0xBE],
              'Progressive Hookshot': [0x0B, 0x80, 0x2E, 0xD7, 0x00, 0xDD],
              'Hammer': [0x11, 0x80, 0x41, 0x38, 0x00, 0xF6],
              'Slingshot': [0x49, 0x80, 0x73, 0xED, 0x01, 0x7B],
              'Boomerang': [0x0E, 0x80, 0x34, 0x35, 0x00, 0xE8],
              'Bomb Bag': [0x4F, 0x80, 0x1A, 0xD8, 0x00, 0xBF],
              'Lens of Truth': [0x0F, 0x80, 0x36, 0x39, 0x00, 0xEA],
              'Dins Fire': [0x05, 0x80, 0x64, 0xAD, 0x01, 0x5D],
              'Farores Wind': [0x0D, 0x80, 0x65, 0xAE, 0x01, 0x5D],
              'Nayrus Love': [0x13, 0x80, 0x66, 0xAF, 0x01, 0x5D],
              'Fire Arrows': [0x04, 0x80, 0x60, 0x70, 0x01, 0x58],
              'Ice Arrows': [0x0C, 0x80, 0x61, 0x71, 0x01, 0x58],
              'Light Arrows': [0x12, 0x80, 0x62, 0x72, 0x01, 0x58],
              'Bottle': [0x14, 0x80, 0x01, 0x42, 0x00, 0xC6],
              'Bottle with Letter': [0x1B, 0x80, 0x45, 0x99, 0x01, 0x0B],
              'Bottle with Milk': [0x1A, 0x80, 0x30, 0x98, 0x00, 0xDF],
              'Pocket Egg': [0x2D, 0x80, 0x29, 0x01, 0x00, 0xDA],
              'Pocket Cucco': [0x2E, 0x80, 0x44, 0x0B, 0x01, 0x09],
              'Cojiro': [0x2F, 0x80, 0x5E, 0x02, 0x01, 0x09],
              'Odd Mushroom': [0x30, 0x80, 0x54, 0x03, 0x01, 0x41],
              'Odd Potion': [0x31, 0x80, 0x53, 0x04, 0x01, 0x40],
              'Poachers Saw': [0x32, 0x80, 0x40, 0x05, 0x00, 0xF5],
              'Broken Sword': [0x33, 0x80, 0x56, 0x08, 0x01, 0x43],
              'Prescription': [0x34, 0x80, 0x57, 0x09, 0x01, 0x46],
              'Eyeball Frog': [0x35, 0x80, 0x5A, 0x0D, 0x01, 0x49],
              'Eyedrops': [0x36, 0x80, 0x52, 0x0E, 0x01, 0x3F],
              'Claim Check': [0x37, 0x80, 0x55, 0xA4, 0x01, 0x8D],
              'Kokiri Sword': [0x3B, 0x80, 0x74, 0xA4, 0x01, 0x8D],
              'Biggoron Sword': [0x3D, 0x80, 0x43, 0x0C, 0x00, 0xF8],
              'Deku Shield': [0x3E, 0xA0, 0xE3, 0x4C, 0x00, 0xCB],
              'Hylian Shield': [0x3F, 0xA0, 0xD4, 0x4D, 0x00, 0xDC],
              'Mirror Shield': [0x40, 0x80, 0x3A, 0x4E, 0x00, 0xEE],
              'Goron Tunic': [0x42, 0xA0, 0x3C, 0x50, 0x00, 0xF2],
              'Zora Tunic': [0x43, 0xA0, 0x3D, 0x51, 0x00, 0xF2],
              'Iron Boots': [0x45, 0x80, 0x47, 0x53, 0x01, 0x18],
              'Hover Boots': [0x46, 0x80, 0x5F, 0x54, 0x01, 0x57],
              'Progressive Strength Upgrade': [0x52, 0x80, 0x4A, 0xD9, 0x01, 0x2D],
              'Progressive Scale': [0x54, 0x80, 0x2B, 0xE8, 0x00, 0xDB],
              'Progressive Wallet': [0x57, 0x80, 0x23, 0xE9, 0x00, 0xD1],
              'Deku Stick Capacity': [0x98, 0x80, 0xE5, 0xEA, 0x00, 0xC7],
              'Deku Nut Capacity': [0x9A, 0x80, 0xEE, 0xEC, 0x00, 0xBB],
              'Stone of Agony': [0x6F, 0x80, 0x21, 0x68, 0x00, 0xC8],
              'Piece of Heart': [0x7A, 0x80, 0x14, 0xC2, 0x00, 0xBD],
              'Recovery Heart': [0x83, 0x80, 0x09, 0x55, 0x00, 0xB7],
              'Arrows (5)': [0x92, 0x48, 0xDB, 0xE6, 0x00, 0xD8],
              'Arrows (10)': [0x93, 0x4A, 0xDA, 0xE6, 0x00, 0xD8],
              'Arrows (30)': [0x94, 0x4A, 0xD9, 0xE6, 0x00, 0xD8],
              'Bombs (5)': [0x8E, 0x59, 0xE0, 0x32, 0x00, 0xCE],
              'Bombs (10)': [0x8F, 0x59, 0xE0, 0x32, 0x00, 0xCE],
              'Bombs (20)': [0x90, 0x59, 0xE0, 0x32, 0x00, 0xCE],
              'Bombchus (5)': [0x96, 0x80, 0xD8, 0x33, 0x00, 0xD9],
              'Bombchus (10)': [0x09, 0x80, 0xD8, 0x33, 0x00, 0xD9],
              'Bombchus (20)': [0x97, 0x80, 0xD8, 0x33, 0x00, 0xD9],
              'Deku Nuts (5)': [0x8C, 0x0C, 0xEE, 0x34, 0x00, 0xBB],
              'Deku Nuts (10)': [0x8D, 0x0C, 0xEE, 0x34, 0x00, 0xBB],
              'Rupee (1)': [0x84, 0x00, 0x93, 0x6F, 0x01, 0x7F],
              'Rupees (5)': [0x85, 0x01, 0x92, 0xCC, 0x01, 0x7F],
              'Rupees (20)': [0x86, 0x02, 0x91, 0xF0, 0x01, 0x7F],
              'Rupees (50)': [0x87, 0x14, 0x8F, 0xF1, 0x01, 0x7F],
              'Rupees (200)': [0x88, 0x13, 0x8E, 0xF2, 0x01, 0x7F],
              'Ice Trap': [0x85, 0x01, 0x92, 0xCC, 0x01, 0x7F], # Ice Trap in special spots will become a blue rupee.
              'Zeldas Lullaby': 0xD4,
              'Eponas Song': 0xD2,
              'Suns Song': 0xD3,
              'Sarias Song': 0xD1,
              'Song of Time': 0xD5,
              'Song of Storms': 0xD6,
              'Minuet of Forest': 0x73,
              'Bolero of Fire': 0x74,
              'Serenade of Water': 0x75,
              'Nocturne of Shadow': 0x77,
              'Requiem of Spirit': 0x76,
              'Prelude of Light': 0x78,
              'Kokiri Emerald': [0x04, 0xA5, 0x80, [0x00, 0x04, 0x00, 0x00]],
              'Goron Ruby': [0x08, 0xA5, 0x81, [0x00, 0x08, 0x00, 0x00]],
              'Zora Sapphire': [0x10, 0xA5, 0x82, [0x00, 0x10, 0x00, 0x00]],
              'Forest Medallion': [0x01, 0xA7, 0x3E, [0x00, 0x00, 0x00, 0x01]],
              'Fire Medallion': [0x02, 0xA7, 0x3C, [0x00, 0x00, 0x00, 0x02]],
              'Water Medallion': [0x04, 0xA7, 0x3D, [0x00, 0x00, 0x00, 0x04]],
              'Spirit Medallion': [0x08, 0xA7, 0x3F, [0x00, 0x00, 0x00, 0x08]],
              'Shadow Medallion': [0x10, 0xA7, 0x41, [0x00, 0x00, 0x00, 0x10]],
              'Light Medallion': [0x20, 0xA7, 0x40, [0x00, 0x00, 0x00, 0x20]]}
