from ....tl.mtproto_request import MTProtoRequest


class SendInlineBotResultRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.sendInlineBotResult#b16e06fe flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int random_id:long query_id:long id:string = Updates"""

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

    def __init__(self, peer, random_id, query_id, id, silent=None, background=None, clear_draft=None, reply_to_msg_id=None):
        """
        :param silent: Telegram type: «true».
        :param background: Telegram type: «true».
        :param clear_draft: Telegram type: «true».
        :param peer: Telegram type: «InputPeer».
        :param reply_to_msg_id: Telegram type: «int».
        :param random_id: Telegram type: «long».
        :param query_id: Telegram type: «long».
        :param id: Telegram type: «string».

        :returns Updates: Instance of either UpdatesTooLong, UpdateShortMessage, UpdateShortChatMessage, UpdateShort, UpdatesCombined, UpdatesTg, UpdateShortSentMessage.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.silent = silent
        self.background = background
        self.clear_draft = clear_draft
        self.peer = peer
        self.reply_to_msg_id = reply_to_msg_id
        self.random_id = random_id
        self.query_id = query_id
        self.id = id

    def on_send(self, writer):
        writer.write_int(SendInlineBotResultRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 5) if self.silent else 0
        flags |= (1 << 6) if self.background else 0
        flags |= (1 << 7) if self.clear_draft else 0
        flags |= (1 << 0) if self.reply_to_msg_id else 0
        writer.write_int(flags)

        self.peer.on_send(writer)
        if self.reply_to_msg_id:
            writer.write_int(self.reply_to_msg_id)

        writer.write_long(self.random_id)
        writer.write_long(self.query_id)
        writer.tgwrite_string(self.id)

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

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

    def __repr__(self):
        return 'messages.sendInlineBotResult#b16e06fe flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int random_id:long query_id:long id:string = Updates'

    def __str__(self):
        return '(messages.sendInlineBotResult (ID: 0xb16e06fe) = (silent={}, background={}, clear_draft={}, peer={}, reply_to_msg_id={}, random_id={}, query_id={}, id={}))'.format(str(self.silent), str(self.background), str(self.clear_draft), str(self.peer), str(self.reply_to_msg_id), str(self.random_id), str(self.query_id), str(self.id))
