from telethon.tl.mtproto_request import MTProtoRequest


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

    # Telegram's constructor ID (and unique identifier) for this class
    constructor_id = 0x6319d612

    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».
        """
        super().__init__()

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

    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 (all attributes are 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:None mask:flags.1?true alt:string stickerset:InputStickerSet mask_coords:flags.0?MaskCoords = DocumentAttribute'

    def __str__(self):
        return '(documentAttributeSticker (ID: 0x6319d612) = (mask={}, alt={}, stickerset={}, mask_coords={}))'.format(str(self.mask), str(self.alt), str(self.stickerset), str(self.mask_coords))
