from telethon.tl.mtproto_request import MTProtoRequest


class StickerSet(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    stickerSet#cd303b41 flags:None installed:flags.0?true archived:flags.1?true official:flags.2?true masks:flags.3?true id:long access_hash:long title:string short_name:string count:int hash:int = StickerSet"""

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

    def __init__(self, id, access_hash, title, short_name, count, hash, installed=None, archived=None, official=None, masks=None):
        """
        :param installed: Telegram type: «true».
        :param archived: Telegram type: «true».
        :param official: Telegram type: «true».
        :param masks: Telegram type: «true».
        :param id: Telegram type: «long».
        :param access_hash: Telegram type: «long».
        :param title: Telegram type: «string».
        :param short_name: Telegram type: «string».
        :param count: Telegram type: «int».
        :param hash: Telegram type: «int».
        """
        super().__init__()

        self.installed = installed
        self.archived = archived
        self.official = official
        self.masks = masks
        self.id = id
        self.access_hash = access_hash
        self.title = title
        self.short_name = short_name
        self.count = count
        self.hash = hash

    def on_send(self, writer):
        writer.write_int(StickerSet.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.installed else 0
        flags |= (1 << 1) if self.archived else 0
        flags |= (1 << 2) if self.official else 0
        flags |= (1 << 3) if self.masks else 0
        writer.write_int(flags)

        writer.write_long(self.id)
        writer.write_long(self.access_hash)
        writer.tgwrite_string(self.title)
        writer.tgwrite_string(self.short_name)
        writer.write_int(self.count)
        writer.write_int(self.hash)

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are None)"""
        return StickerSet(None, None, None, None, None, None, None, None, None, None)

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

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

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

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

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

        self.id = reader.read_long()
        self.access_hash = reader.read_long()
        self.title = reader.tgread_string()
        self.short_name = reader.tgread_string()
        self.count = reader.read_int()
        self.hash = reader.read_int()

    def __repr__(self):
        return 'stickerSet#cd303b41 flags:None installed:flags.0?true archived:flags.1?true official:flags.2?true masks:flags.3?true id:long access_hash:long title:string short_name:string count:int hash:int = StickerSet'

    def __str__(self):
        return '(stickerSet (ID: 0xcd303b41) = (installed={}, archived={}, official={}, masks={}, id={}, access_hash={}, title={}, short_name={}, count={}, hash={}))'.format(str(self.installed), str(self.archived), str(self.official), str(self.masks), str(self.id), str(self.access_hash), str(self.title), str(self.short_name), str(self.count), str(self.hash))
