from abc import ABC
import log
class Business(ABC):
    def __init__(self,id,production,balance) -> None:
        """production (dict): {
                                name: 'Gem',
                                amount: 4,
                                craft: {
                                    'Raw_Gem': 4,
                                    'Tool_Gem': 0.2,
                                }
                            }
        balance (int): Starting Balance 
        """
        self.id=id
        self.production=production
        self.balance_history=[balance]
        self.balance=balance
        #Setup Inventory
        self.inventory={production["name"]: 0}
        for l in production["prod"]:
            for k,v in l.items():
                self.inventory[k]=0
        pass

    def tick(self,step):
        self.tick_business_decisions(step)

    def tick_business_decisions(self,step):
        assert "no business decision method has been created"
        pass

    def tick_episode(self,episode_count):
        """
        Call for resetting for the next episode
        """
        self.balance_history.append(self.balance)
        self.tick_business_episode(episode_count)

    
    def tick_business_episode(self,episode_count):
        """
        Call for resetting for the next episode
        """
        assert "no business episode tick method has been created"

    def close_business(self):
        assert "close_business has not been provided"
        
    def log(self,episode,episode_length,step):
        data={}
        data["id"]=self.id
        data["episode"]=episode
        data["step"]=step
        data["tstep"]=step+episode*episode_length
        data["production"]=self.production["name"]
        data["balance"]=self.balance
        log.BUSINESSData.append(data)