from .base_business import Business
from ..agents.price_believe_aquire import Price_Believe_Aquire_Agent
from ..agents.price_believe_distribute import Price_Believe_Distribiute_Agent
from ..agents.autoproduction import AutoProductionAgent

class Price_Believe_Business(Business):
    def __init__(self, id, production, balance,exchange,simulation) -> None:
      super().__init__(id, production, balance)
      
      self.distribute=Price_Believe_Distribiute_Agent(simulation,self,production["name"],exchange,0.5,10)
      self.craft=AutoProductionAgent(simulation,self)
      self.aquire={}
      for l in production["prod"]:
        for k,v in l.items():
          a=Price_Believe_Aquire_Agent(simulation,self,k,exchange,1,10)
          a.set_target(v*2)
          a.set_price_max(10)
          self.aquire[k]=a
      self.distribute.set_price_min(10)
      self.distribute.set_target(0)

    def tick_business_decisions(self,step):
        for comp in self.production["prod"]:
          for k,v in comp.items():
            modifier=1
            self.aquire[k].set_target(v*modifier)
        max_amount=self.production["amount"]*5
        self.craft.set_target(max_amount)

    def resource_in_possesion(self):
      return self.distribute.open_qty+self.inventory[self.production["name"]]

    def close_business(self):
      for k,a in self.aquire.items():
        a.unregister()
      self.distribute.unregister()
      self.craft.unregister()