from HabitBaseModel import HabitBaseModel
from AllDBFields import HeroDbFields
from Zone import Zone
from Monster import Monster








class Hero(HabitBaseModel):
  """
    This is a wrapper for the hero data from the database
  """
  
  @classmethod
  def construct_unsaved_hero(cls,accountPk = None,shipName = ""):
    """
      args:
        accountPk: 
          an objectId for the accounts collection
        shipName:
          string. self-explainatory
      returns:
        an instance of the Hero class. Doesn't exist in db
    """
    import uuid
    zoneVisitCounts = {}
    homeZone = Zone.get_home_zone()
    zonesChoices = []
    zonesChoices.append(Zone.construct_next_zone_choice(1,zoneVisitCounts,True))
    zonesChoices.append(Zone.construct_next_zone_choice(1,zoneVisitCounts))
    zonesChoices.append(Zone.construct_next_zone_choice(1,zoneVisitCounts))
    homeZone.nextZoneReferenceList = zonesChoices
    hero = {
      HeroDbFields.ACCOUNT_PK_KEY: accountPk,
      HeroDbFields.SHIP_NAME: shipName,
      HeroDbFields.LVL:1,
      HeroDbFields.GOLD:0,
      HeroDbFields.MAX_HP: 100,
      HeroDbFields.NOW_HP: 100,
      HeroDbFields.MAX_XP: 50,
      HeroDbFields.NOW_XP: 0,
      HeroDbFields.ATTACK_LVL: 1,
      HeroDbFields.DEFENSE_LVL: 1,
      HeroDbFields.PUBLIC_KEY: uuid.uuid4().hex,
      HeroDbFields.ZONE_VISIT_COUNTS: zoneVisitCounts,
      HeroDbFields.ZONE: homeZone.dict
    }
    heroObj = cls.construct_model_from_dict(hero)
    return heroObj

  @classmethod
  def construct_new_hero_in_db(cls,accountPk = None,shipName = ""):
    """
      args:
        accountPk: 
          an objectId for the accounts collection
        shipName:
          string. self-explainatory
      returns:
        an objectId for the heros collection
    """
    heroObj = Hero.construct_unsaved_hero(accountPk,shipName)
    heroObj.save_changes()
    return heroObj.get_pk()

  def __init__(self):