from ....tl.mtproto_request import MTProtoRequest


class GetBotCallbackAnswerRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.getBotCallbackAnswer#810a9fec flags:# game:flags.1?true peer:InputPeer msg_id:int data:flags.0?bytes = messages.BotCallbackAnswer"""

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

    def __init__(self, peer, msg_id, game=None, data=None):
        """
        :param game: Telegram type: «true».
        :param peer: Telegram type: «InputPeer».
        :param msg_id: Telegram type: «int».
        :param data: Telegram type: «bytes».

        :returns messages.BotCallbackAnswer: Instance of BotCallbackAnswer.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.game = game
        self.peer = peer
        self.msg_id = msg_id
        self.data = data

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

        self.peer.on_send(writer)
        writer.write_int(self.msg_id)
        if self.data:
            writer.tgwrite_bytes(self.data)

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

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

    def __repr__(self):
        return 'messages.getBotCallbackAnswer#810a9fec flags:# game:flags.1?true peer:InputPeer msg_id:int data:flags.0?bytes = messages.BotCallbackAnswer'

    def __str__(self):
        return '(messages.getBotCallbackAnswer (ID: 0x810a9fec) = (game={}, peer={}, msg_id={}, data={}))'.format(str(self.game), str(self.peer), str(self.msg_id), str(self.data))
