from ...tl.mtproto_request import MTProtoRequest


class InputStickerSetItem(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    inputStickerSetItem#ffa0a496 flags:# document:InputDocument emoji:string mask_coords:flags.0?MaskCoords = InputStickerSetItem"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0xffa0a496
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0xae59f075

    def __init__(self, document, emoji, mask_coords=None):
        """
        :param document: Telegram type: "InputDocument".
        :param emoji: Telegram type: "string".
        :param mask_coords: Telegram type: "MaskCoords".

        Constructor for InputStickerSetItem: Instance of InputStickerSetItem.
        """
        super().__init__()

        self.document = document
        self.emoji = emoji
        self.mask_coords = mask_coords

    def to_dict(self):
        return {
            'document': None if self.document is None else self.document.to_dict(),
            'emoji': self.emoji,
            'mask_coords': None if self.mask_coords is None else self.mask_coords.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(InputStickerSetItem.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.mask_coords else 0
        writer.write_int(flags)

        self.document.on_send(writer)
        writer.tgwrite_string(self.emoji)
        if self.mask_coords:
            self.mask_coords.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return InputStickerSetItem(None, None, None)

    def on_response(self, reader):
        flags = reader.read_int()

        self.document = reader.tgread_object()
        self.emoji = reader.tgread_string()
        if (flags & (1 << 0)) != 0:
            self.mask_coords = reader.tgread_object()

    def __repr__(self):
        return 'inputStickerSetItem#ffa0a496 flags:# document:InputDocument emoji:string mask_coords:flags.0?MaskCoords = InputStickerSetItem'

    def __str__(self):
        return '(inputStickerSetItem (ID: 0xffa0a496) = (document={}, emoji={}, mask_coords={}))'.format(str(self.document), str(self.emoji), str(self.mask_coords))
