def __init__(self, id=None, name=None, members=None, tradeable=None, tradeable_on_ge=None, stackable=None,
                 noted=None, noteable=None, linked_id=None, placeholder=None, equipable=None, equipable_by_player=None,
                 cost=None, lowalch=None, highalch=None, weight=None, buy_limit=None, quest_item=None,
                 release_date=None, examine=None, url=None, equipment=None):
        self.id = id
        self.name = name
        self.members = members
        self.tradeable = tradeable
        self.tradeable_on_ge = tradeable_on_ge
        self.stackable = stackable
        self.noted = noted
        self.noteable = noteable
        self.linked_id = linked_id
        self.placeholder = placeholder
        self.equipable = equipable
        self.equipable_by_player = equipable_by_player
        self.cost = cost
        self.lowalch = lowalch
        self.highalch = highalch
        self.weight = weight
        self.buy_limit = buy_limit
        self.quest_item = quest_item
        self.release_date = release_date
        self.examine = examine
        self.url = url

        self.equipment: Optional[ItemEquipment] = None

        if self.equipable_by_player:
            self.equipment = ItemEquipment(**equipment)
    def from_json(cls, json_dict: Dict) -> "ItemDefinition":
        """Convert the dictionary under the 'equipment' key into actual :class:`ItemEquipment`"""
        if json_dict.get("equipable_by_player"):
            equipment = json_dict.pop("equipment")
            json_dict["equipment"] = ItemEquipment(**equipment)

        if json_dict.get("weapon"):
            weapon = json_dict.pop("weapon")
            json_dict["weapon"] = ItemWeapon(**weapon)

        return cls(**json_dict)
    def from_json(cls, json_dict: Dict) -> 'ItemProperties':
        """Construct ItemProperties object from dictionary/JSON."""
        # Convert the dictionary under the 'equipment' key into ItemEquipment.
        if json_dict.get("equipable_by_player"):
            equipment = json_dict.pop("equipment")
            json_dict["equipment"] = ItemEquipment(**equipment)

        # Convert the dictionary under the 'weapon' key into ItemWeapon.
        if json_dict.get("weapon"):
            weapon = json_dict.pop("weapon")
            json_dict["weapon"] = ItemWeapon(**weapon)

        return cls(**json_dict)
class ItemDefinition:
    """This class defines the object structure and properties for an OSRS item.

    The ItemDefinition class is the object that retains all properties and stats
    for one specific item. Every item has the properties defined in this class.
    Equipable items have additional properties defined in the linked ItemEquipment
    class.
    """

    def __init__(self, id=None, name=None, members=None, tradeable=None, tradeable_on_ge=None, stackable=None,
                 noted=None, noteable=None, linked_id=None, placeholder=None, equipable=None, equipable_by_player=None,
                 cost=None, lowalch=None, highalch=None, weight=None, buy_limit=None, quest_item=None,
                 release_date=None, examine=None, url=None, equipment=None):
        self.id = id
        self.name = name
        self.members = members
        self.tradeable = tradeable
        self.tradeable_on_ge = tradeable_on_ge
        self.stackable = stackable
        self.noted = noted
        self.noteable = noteable
        self.linked_id = linked_id
        self.placeholder = placeholder
        self.equipable = equipable
        self.equipable_by_player = equipable_by_player
        self.cost = cost
        self.lowalch = lowalch
        self.highalch = highalch
        self.weight = weight
        self.buy_limit = buy_limit
        self.quest_item = quest_item
        self.release_date = release_date
        self.examine = examine
        self.url = url

        self.equipment: Optional[ItemEquipment] = None

        if self.equipable_by_player:
            self.equipment = ItemEquipment(**equipment)

    def construct_json(self) -> Dict:
        """Construct dictionary/JSON for exporting or printing.

        :return json_out: All class attributes stored in a dictionary.
        """
        json_out: Dict = dict()

        for prop in self.__dict__:
            if prop == "equipment":
                continue
            json_out[prop] = getattr(self, prop)

        if self.equipable_by_player:
            json_out["equipment"] = self.equipment.construct_json()

        return json_out

    def export_json(self, pretty: bool, export_path: str):
        """Output Item to JSON file.

        :param pretty: Toggles pretty (indented) JSON output.
        :param export_path: The folder location to save the JSON output to.
        """
        json_out = self.construct_json()
        out_file_name = str(self.id) + ".json"
        out_file_path = os.path.join(export_path, out_file_name)
        with open(out_file_path, "w") as out_file:
            if pretty:
                json.dump(json_out, out_file, indent=4)
            else:
                json.dump(json_out, out_file)