# Generated from the eo-protocol XML specification.
#
# This file should not be modified.
# Changes will be lost when code is regenerated.

from ...serialization_error import SerializationError
from ....data.eo_writer import EoWriter
from ....data.eo_reader import EoReader

class Spell:
    """
    A spell known by the player
    """
    _byte_size: int = 0
    _id: int = None # type: ignore [assignment]
    _level: int = None # type: ignore [assignment]

    @property
    def byte_size(self) -> int:
        """
        Returns the size of the data that this was deserialized from.

        Returns:
            int: The size of the data that this was deserialized from.
        """
        return self._byte_size

    @property
    def id(self) -> int:
        """
        Note:
          - Value range is 0-64008.
        """
        return self._id

    @id.setter
    def id(self, id: int) -> None:
        """
        Note:
          - Value range is 0-64008.
        """
        self._id = id

    @property
    def level(self) -> int:
        """
        Note:
          - Value range is 0-64008.
        """
        return self._level

    @level.setter
    def level(self, level: int) -> None:
        """
        Note:
          - Value range is 0-64008.
        """
        self._level = level

    @staticmethod
    def serialize(writer: EoWriter, data: "Spell") -> None:
        """
        Serializes an instance of `Spell` to the provided `EoWriter`.

        Args:
            writer (EoWriter): The writer that the data will be serialized to.
            data (Spell): The data to serialize.
        """
        if data._id is None:
            raise SerializationError("id must be provided.")
        writer.add_short(data._id)
        if data._level is None:
            raise SerializationError("level must be provided.")
        writer.add_short(data._level)

    @staticmethod
    def deserialize(reader: EoReader) -> "Spell":
        """
        Deserializes an instance of `Spell` from the provided `EoReader`.

        Args:
            reader (EoReader): The writer that the data will be serialized to.

        Returns:
            Spell: The data to serialize.
        """
        data: Spell = Spell()
        old_chunked_reading_mode: bool = reader.chunked_reading_mode
        try:
            reader_start_position: int = reader.position
            data._id = reader.get_short()
            data._level = reader.get_short()
            data._byte_size = reader.position - reader_start_position
            return data
        finally:
            reader.chunked_reading_mode = old_chunked_reading_mode

    def __repr__(self):
        return f"Spell(byte_size={repr(self._byte_size)}, id={repr(self._id)}, level={repr(self._level)})"
