from telethon.tl.mtproto_request import MTProtoRequest


class SetBotCallbackAnswerRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.setBotCallbackAnswer#c927d44b flags:None alert:flags.1?true query_id:long message:flags.0?string url:flags.2?string = Bool"""

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

    def __init__(self, query_id, alert=None, message=None, url=None):
        """
        :param alert: Telegram type: «true».
        :param query_id: Telegram type: «long».
        :param message: Telegram type: «string».
        :param url: Telegram type: «string».
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.alert = alert
        self.query_id = query_id
        self.message = message
        self.url = url

    def on_send(self, writer):
        writer.write_int(SetBotCallbackAnswerRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 1) if self.alert else 0
        flags |= (1 << 0) if self.message else 0
        flags |= (1 << 2) if self.url else 0
        writer.write_int(flags)

        writer.write_long(self.query_id)
        if self.message:
            writer.tgwrite_string(self.message)

        if self.url:
            writer.tgwrite_string(self.url)

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

    def on_response(self, reader):
        self.result = reader.tgread_object()

    def __repr__(self):
        return 'messages.setBotCallbackAnswer#c927d44b flags:None alert:flags.1?true query_id:long message:flags.0?string url:flags.2?string = Bool'

    def __str__(self):
        return '(messages.setBotCallbackAnswer (ID: 0xc927d44b) = (alert={}, query_id={}, message={}, url={}))'.format(str(self.alert), str(self.query_id), str(self.message), str(self.url))
