# generated by scripts/generate_messages.py

from typing import Any, Dict

from twnet_parser.pretty_print import PrettyPrint
from twnet_parser.packer import Unpacker
from twnet_parser.packer import pack_int

class ObjPickup(PrettyPrint):
    def __init__(
            self,
            x: int = 0,
            y: int = 0,
            type: int = 0,
            subtype: int = 0
    ) -> None:
        self.item_name: str = 'item.pickup'
        self.type_id: int = 4
        self.id: int = 0
        self.size: int = 4

        self.x: int = x
        self.y: int = y
        self.type: int = type
        self.subtype: int = subtype

    def __iter__(self):
        yield 'item_name', self.item_name
        yield 'type_id', self.type_id
        yield 'id', self.id
        yield 'size', self.size

        yield 'x', self.x
        yield 'y', self.y
        yield 'type', self.type
        yield 'subtype', self.subtype

    def to_dict_payload_only(self) -> Dict[str, Any]:
        return {
            'x': self.x,
            'y': self.y,
            'type': self.type,
            'subtype': self.subtype
        }

    # first byte of data
    # has to be the first byte of the message payload
    # NOT the chunk header and NOT the message id
    def unpack(self, unpacker: Unpacker) -> bool:
        self.x = unpacker.get_int()
        self.y = unpacker.get_int()
        self.type = unpacker.get_int()
        self.subtype = unpacker.get_int()
        return True

    def pack(self) -> bytes:
        return pack_int(self.x) + \
            pack_int(self.y) + \
            pack_int(self.type) + \
            pack_int(self.subtype)