import time

from .mod import Handler
from .pogoAPI.inventory import items


class inventoryHandler(Handler):

    # Get profile
    def getProfile(self):
        self.logger.info("Printing Profile:")
        profile = self.session.checkProfile()
        self.logger.info(profile)

    # Do Inventory stuff
    def getInventory(self):
        self.logger.info("Get Inventory:")
        self.logger.info(self.session.checkInventory())


    # A very brute force approach to evolving
    def evolveAllPokemon(self):
        inventory = self.session.checkInventory()
        for pokemon in inventory["party"]:
            self.logger.info(self.session.evolvePokemon(pokemon))
            time.sleep(1)


    # You probably don't want to run this
    def releaseAllPokemon(self):
        inventory = self.session.checkInventory()
        for pokemon in inventory["party"]:
            self.session.releasePokemon(pokemon)
            time.sleep(1)


    # Just incase you didn't want any revives
    def tossRevives(self):
        bag = self.session.checkInventory()["bag"]
        return self.session.recycleItem(items.REVIVE, bag[items.REVIVE])


    # Set an egg to an incubator
    def setEgg(self):
        inventory = self.session.checkInventory()

        # If no eggs, nothing we can do
        if len(inventory["eggs"]) == 0:
            return None

        egg = inventory["eggs"][0]
        incubator = inventory["incubators"][0]
        return self.session.setEgg(incubator, egg)

    def cleanInventory(self):
        self.logger.info("Cleaning out Inventory...")
        bag = self.session.checkInventory().bag
        itemsCount, maxItems = self.session.getter.getInventoryCapacity()
        self.logger.info("Inventory capacity {0}/{1}".format(itemsCount, maxItems))
        if (itemsCount/maxItems) < .9: return
        # Clear out all of a crtain type
        tossable = [items.POTION, items.SUPER_POTION, items.HYPER_POTION, items.REVIVE]
        for toss in tossable:
            if toss in bag:
                self.session.recycleItem(toss, bag[toss])

        # Limit a certain type
        limited = {
            items.POKE_BALL: 50,
            items.GREAT_BALL: 75,
            items.ULTRA_BALL: 150,
            items.RAZZ_BERRY: 15,
            items.REVIVE: 10,
            items.MAX_POTION: 20
        }
        for limit in limited:
            if limit in bag and int(bag[limit]) > limited[limit]:
                self.session.recycleItem(limit, bag[limit] - limited[limit])
                time.sleep(.2)
import time

from .mod import Handler
from .pogoAPI.inventory import items


class inventoryHandler(Handler):

    # Get profile
    def getProfile(self):
        self.logger.info("Printing Profile:")
        profile = self.session.checkProfile()
        self.logger.info(profile)

    # Do Inventory stuff
    def getInventory(self):
        self.logger.info("Get Inventory:")
        self.logger.info(self.session.checkInventory())


    # A very brute force approach to evolving
    def evolveAllPokemon(self):
        inventory = self.session.checkInventory()
        for pokemon in inventory["party"]:
            self.logger.info(self.session.evolvePokemon(pokemon))
            time.sleep(1)


    # You probably don't want to run this
    def releaseAllPokemon(self):
        inventory = self.session.checkInventory()
        for pokemon in inventory["party"]:
            self.session.releasePokemon(pokemon)
            time.sleep(1)


    # Just incase you didn't want any revives
    def tossRevives(self):
        bag = self.session.checkInventory()["bag"]
        return self.session.recycleItem(items.REVIVE, bag[items.REVIVE])


    # Set an egg to an incubator
    def setEgg(self):
        inventory = self.session.checkInventory()

        # If no eggs, nothing we can do
        if len(inventory["eggs"]) == 0:
            return None

        egg = inventory["eggs"][0]
        incubator = inventory["incubators"][0]
        return self.session.setEgg(incubator, egg)

    def cleanInventory(self):
        self.logger.info("Cleaning out Inventory...")
        bag = self.session.checkInventory().bag
        itemsCount, maxItems = self.session.getter.getInventoryCapacity()
        self.logger.info("Inventory capacity {0}/{1}".format(itemsCount, maxItems))
        if (itemsCount/maxItems) < .9: return
        # Clear out all of a crtain type
        tossable = [items.POTION, items.SUPER_POTION, items.HYPER_POTION, items.REVIVE]
        for toss in tossable:
            if toss in bag:
                self.session.recycleItem(toss, bag[toss])

        # Limit a certain type
        limited = {
            items.POKE_BALL: 50,
            items.GREAT_BALL: 75,
            items.ULTRA_BALL: 150,
            items.RAZZ_BERRY: 15,
            items.REVIVE: 10,
            items.MAX_POTION: 20
        }
        for limit in limited:
            if limit in bag and int(bag[limit]) > limited[limit]:
                self.session.recycleItem(limit, bag[limit] - limited[limit])
                time.sleep(.2)
# Get profile # Do Inventory stuff # A very brute force approach to evolving # You probably don't want to run this # Just incase you didn't want any revives # Set an egg to an incubator # If no eggs, nothing we can do # Clear out all of a crtain type # Limit a certain type