# -*- coding: utf-8 -*-
"""
Item Sets
 - ItemSet.dbc
"""

from .. import *
from ..globalstrings import *


class ItemSet(Model):
	pass

class ItemSetTooltip(Tooltip):
	def tooltip(self):
		
		items = self.obj.getItems()
		maxItems = len(items)
		
		self.append("name", ITEM_SET_NAME % (self.obj.getName(), 0, maxItems), color=YELLOW)
		
		for item in items:
			self.append("item", "  %s" % (item.getName()), color=GREY)
		
		for bonus, pieces in self.obj.getBonusInfo():
			self.append("bonus", ITEM_SET_BONUS_GRAY % (pieces, bonus.getDescription()), color=GREY)
		
		ret = self.values
		self.values = []
		return ret

class ItemSetProxy(object):
	"""
	WDBC proxy for item sets
	"""
	def __init__(self, cls):
		from pywow import wdbc
		self.__file = wdbc.get("ItemSet.dbc", build=-1)
	
	def get(self, id):
		return self.__file[id]
	
	def getBonusInfo(self, row):
		from operator import itemgetter
		from ..spells import Spell
		ret = []
		for i in range(1, 9):
			spell = row._raw("bonus_%i" % (i))
			pieces = getattr(row, "required_items_%i" % (i))
			if spell:
				ret.append((Spell(spell), pieces))
		
		ret.sort(key=itemgetter(1))
		return ret
	
	def getItems(self, row):
		from ..items import Item
		ret = []
		for i in range(1, 18):
			id = row._raw("item_%i" % (i))
			if id:
				ret.append(Item(id))
		
		return ret
	
	def getName(self, row):
		return row.name_enus

ItemSet.initProxy(ItemSetProxy)

@@ -326,24 +326,226 @@
 =YELLOW)%0A%09%09%0A
+%09%09requiredSkill, requiredSkillLevel = self.obj.getRequiredSkillInfo()%0A%09%09if requiredSkill and requiredSkillLevel:%0A%09%09%09self.append(%22requiredSkill%22, ITEM_MIN_SKILL %25 (requiredSkill, requiredSkillLevel))%0A%09%09%0A
 %09%09for item i
@@ -1514,32 +1514,236 @@
 %0A%09%09return ret%0A%09%0A
+%09def getRequiredSkillInfo(self, row):%0A%09%09requiredSkillLevel = row.required_skill_level%0A%09%09if row.required_skill:%0A%09%09%09return row.required_skill.name_enus, requiredSkillLevel%0A%09%09return %22%22, requiredSkillLevel%0A%09%0A
 %09def getName(sel

Add ItemSet.getRequiredSkillInfo()