from ...tl.mtproto_request import MTProtoRequest


class TextUrl(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    textUrl#3c2884c1 text:RichText url:string webpage_id:long = RichText"""

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

    def __init__(self, text, url, webpage_id):
        """
        :param text: Telegram type: «RichText».
        :param url: Telegram type: «string».
        :param webpage_id: Telegram type: «long».

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

        self.text = text
        self.url = url
        self.webpage_id = webpage_id

    def on_send(self, writer):
        writer.write_int(TextUrl.constructor_id, signed=False)
        self.text.on_send(writer)
        writer.tgwrite_string(self.url)
        writer.write_long(self.webpage_id)

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

    def on_response(self, reader):
        self.text = reader.tgread_object()
        self.url = reader.tgread_string()
        self.webpage_id = reader.read_long()

    def __repr__(self):
        return 'textUrl#3c2884c1 text:RichText url:string webpage_id:long = RichText'

    def __str__(self):
        return '(textUrl (ID: 0x3c2884c1) = (text={}, url={}, webpage_id={}))'.format(str(self.text), str(self.url), str(self.webpage_id))
