class WorkingMemory:
    def __init__(self):
        self.memory = {}
        self.capacity = 80  # Maximum number of lines to store in memory

    def initialize(self):
        print("Initializing working_memory...")
        self.load_initial_data()

    def load_initial_data(self):
        initial_data = {
            "product1": {"type": "code review tool", "name": "SAGE", "quantity": 4199},
            "product2": {"type": "AI capability", "name": "Eden's Internal Function", "quantity": 15819},
            "product3": {"type": "market research cycle", "name": "EDEN Market Research", "quantity": 1006}
        }
        self.memory.update(initial_data)
        print("Initial data loaded into working_memory.")

    def add_product(self, product_name, product_type, quantity):
        if len(self.memory) < self.capacity:
            entry = {"type": product_type, "name": product_name, "quantity": quantity}
            self.memory[product_name] = entry
            print(f"Added {product_name} to working_memory.")
        else:
            print("Memory is full. Cannot add more data.")

    def update_product(self, product_name, new_quantity):
        if product_name in self.memory:
            self.memory[product_name]["quantity"] = new_quantity
            print(f"Updated quantity of {product_name}.")
        else:
            print("Product not found in working_memory.")

    def remove_product(self, product_name):
        if product_name in self.memory:
            del self.memory[product_name]
            print(f"Removed {product_name} from working_memory.")
        else:
            print("Product not found in working_memory.")

    def retrieve_product_info(self, product_name):
        if product_name in self.memory:
            return self.memory[product_name]
        else:
            print("No such product in working_memory.")
            return None

    def display_memory_contents(self):
        print("Current contents of working_memory:")
        for entry in self.memory.values():
            print(f"Name: {entry['name']}, Type: {entry['type']}, Quantity: {entry['quantity']}")

    def save_state_to_file(self, file_name="working_memory_backup.txt"):
        with open(file_name, "w") as file:
            for key, value in self.memory.items():
                file.write(f"{key}: {value}\n")
        print(f"State saved to {file_name}")

    def load_state_from_file(self, file_name="working_memory_backup.txt"):
        try:
            with open(file_name, "r") as file:
                lines = file.readlines()
                for line in lines:
                    key, value = line.strip().split(": ")
                    self.memory[key] = eval(value)
            print(f"State loaded from {file_name}")
        except FileNotFoundError:
            print("No saved state found.")