from ....tl.mtproto_request import MTProtoRequest


class AllStickers(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    messages.allStickers#edfd405f hash:int sets:Vector<StickerSet> = messages.AllStickers"""

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

    def __init__(self, hash, sets):
        """
        :param hash: Telegram type: "int".
        :param sets: Telegram type: "StickerSet". Must be a list.

        Constructor for messages.AllStickers: Instance of either AllStickersNotModified, AllStickers.
        """
        super().__init__()

        self.hash = hash
        self.sets = sets

    def to_dict(self):
        return {
            'hash': self.hash,
            'sets': [] if self.sets is None else [None if x is None else x.to_dict() for x in self.sets],
        }

    def on_send(self, writer):
        writer.write_int(AllStickers.constructor_id, signed=False)
        writer.write_int(self.hash)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.sets))
        for sets_item in self.sets:
            sets_item.on_send(writer)

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

    def on_response(self, reader):
        self.hash = reader.read_int()
        reader.read_int()  # Vector's constructor ID
        self.sets = []  # Initialize an empty list
        sets_len = reader.read_int()
        for _ in range(sets_len):
            sets_item = reader.tgread_object()
            self.sets.append(sets_item)

    def __repr__(self):
        return 'messages.allStickers#edfd405f hash:int sets:Vector<StickerSet> = messages.AllStickers'

    def __str__(self):
        return '(messages.allStickers (ID: 0xedfd405f) = (hash={}, sets={}))'.format(str(self.hash), None if not self.sets else [str(_) for _ in self.sets])
