from ...tl.mtproto_request import MTProtoRequest


class TextConcat(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    textConcat#7e6260d7 texts:Vector<RichText> = RichText"""

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

    def __init__(self, texts):
        """
        :param texts: Telegram type: «RichText». Must be a list.

        Constructor for RichText: Instance of either TextEmpty, TextPlain, TextBold, TextItalic, TextUnderline, TextStrike, TextFixed, TextUrl, TextEmail, TextConcat.
        """
        super().__init__()

        self.texts = texts

    def on_send(self, writer):
        writer.write_int(TextConcat.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.texts))
        for texts_item in self.texts:
            texts_item.on_send(writer)

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

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

    def __repr__(self):
        return 'textConcat#7e6260d7 texts:Vector<RichText> = RichText'

    def __str__(self):
        return '(textConcat (ID: 0x7e6260d7) = (texts={}))'.format(None if not self.texts else [str(_) for _ in self.texts])
