from ...tl.mtproto_request import MTProtoRequest


class PageBlockEmbedPost(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    pageBlockEmbedPost#292c7be9 url:string webpage_id:long author_photo_id:long author:string date:date blocks:Vector<PageBlock> caption:RichText = PageBlock"""

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

    def __init__(self, url, webpage_id, author_photo_id, author, date, blocks, caption):
        """
        :param url: Telegram type: «string».
        :param webpage_id: Telegram type: «long».
        :param author_photo_id: Telegram type: «long».
        :param author: Telegram type: «string».
        :param date: Telegram type: «date».
        :param blocks: Telegram type: «PageBlock». Must be a list.
        :param caption: Telegram type: «RichText».

        Constructor for PageBlock: Instance of either PageBlockUnsupported, PageBlockTitle, PageBlockSubtitle, PageBlockAuthorDate, PageBlockHeader, PageBlockSubheader, PageBlockParagraph, PageBlockPreformatted, PageBlockFooter, PageBlockDivider, PageBlockAnchor, PageBlockList, PageBlockBlockquote, PageBlockPullquote, PageBlockPhoto, PageBlockVideo, PageBlockCover, PageBlockEmbed, PageBlockEmbedPost, PageBlockCollage, PageBlockSlideshow, PageBlockChannel.
        """
        super().__init__()

        self.url = url
        self.webpage_id = webpage_id
        self.author_photo_id = author_photo_id
        self.author = author
        self.date = date
        self.blocks = blocks
        self.caption = caption

    def on_send(self, writer):
        writer.write_int(PageBlockEmbedPost.constructor_id, signed=False)
        writer.tgwrite_string(self.url)
        writer.write_long(self.webpage_id)
        writer.write_long(self.author_photo_id)
        writer.tgwrite_string(self.author)
        writer.tgwrite_date(self.date)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.blocks))
        for blocks_item in self.blocks:
            blocks_item.on_send(writer)

        self.caption.on_send(writer)

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

    def on_response(self, reader):
        self.url = reader.tgread_string()
        self.webpage_id = reader.read_long()
        self.author_photo_id = reader.read_long()
        self.author = reader.tgread_string()
        self.date = reader.tgread_date()
        reader.read_int()  # Vector's constructor ID
        self.blocks = []  # Initialize an empty list
        blocks_len = reader.read_int()
        for _ in range(blocks_len):
            blocks_item = reader.tgread_object()
            self.blocks.append(blocks_item)

        self.caption = reader.tgread_object()

    def __repr__(self):
        return 'pageBlockEmbedPost#292c7be9 url:string webpage_id:long author_photo_id:long author:string date:date blocks:Vector<PageBlock> caption:RichText = PageBlock'

    def __str__(self):
        return '(pageBlockEmbedPost (ID: 0x292c7be9) = (url={}, webpage_id={}, author_photo_id={}, author={}, date={}, blocks={}, caption={}))'.format(str(self.url), str(self.webpage_id), str(self.author_photo_id), str(self.author), str(self.date), None if not self.blocks else [str(_) for _ in self.blocks], str(self.caption))
