from telethon.tl.mtproto_request import MTProtoRequest


class PageBlockList(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    pageBlockList#3a58c7f4 ordered:Bool items:Vector<RichText> = PageBlock"""

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

    def __init__(self, ordered, items):
        """
        :param ordered: Telegram type: «Bool».
        :param items: Telegram type: «RichText». Must be a list.
        """
        super().__init__()

        self.ordered = ordered
        self.items = items

    def on_send(self, writer):
        writer.write_int(PageBlockList.constructor_id, signed=False)
        writer.tgwrite_bool(self.ordered)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.items))
        for items_item in self.items:
            items_item.on_send(writer)

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

    def on_response(self, reader):
        self.ordered = reader.tgread_bool()
        reader.read_int()  # Vector's constructor ID
        self.items = []  # Initialize an empty list
        items_len = reader.read_int()
        for _ in range(items_len):
            items_item = reader.tgread_object()
            self.items.append(items_item)

    def __repr__(self):
        return 'pageBlockList#3a58c7f4 ordered:Bool items:Vector<RichText> = PageBlock'

    def __str__(self):
        return '(pageBlockList (ID: 0x3a58c7f4) = (ordered={}, items={}))'.format(str(self.ordered), None if not self.items else [str(_) for _ in self.items])
