from ...tl.tlobject import TLObject


class DocumentAttributeSticker(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    documentAttributeSticker#6319d612 flags:# mask:flags.1?true alt:string stickerset:InputStickerSet mask_coords:flags.0?MaskCoords = DocumentAttribute"""

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

    def __init__(self, alt, stickerset, mask=None, mask_coords=None):
        """
        :param mask: Telegram type: "true".
        :param alt: Telegram type: "string".
        :param stickerset: Telegram type: "InputStickerSet".
        :param mask_coords: Telegram type: "MaskCoords".

        Constructor for DocumentAttribute: Instance of either DocumentAttributeImageSize, DocumentAttributeAnimated, DocumentAttributeSticker, DocumentAttributeVideo, DocumentAttributeAudio, DocumentAttributeFilename, DocumentAttributeHasStickers.
        """
        super().__init__()

        self.mask = mask
        self.alt = alt
        self.stickerset = stickerset
        self.mask_coords = mask_coords

    def to_dict(self):
        return {
            'mask': self.mask,
            'alt': self.alt,
            'stickerset': None if self.stickerset is None else self.stickerset.to_dict(),
            'mask_coords': None if self.mask_coords is None else self.mask_coords.to_dict(),
        }

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

        writer.tgwrite_string(self.alt)
        self.stickerset.on_send(writer)
        if self.mask_coords:
            self.mask_coords.on_send(writer)

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

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

        if (flags & (1 << 1)) != 0:
            self.mask = True  # Arbitrary not-None value, no need to read since it is a flag

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

    def __repr__(self):
        return 'documentAttributeSticker#6319d612 flags:# mask:flags.1?true alt:string stickerset:InputStickerSet mask_coords:flags.0?MaskCoords = DocumentAttribute'

    def __str__(self):
        return TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
