from ....tl.tlobject import TLObject
from ....utils import get_input_peer


class GetBotCallbackAnswerRequest(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. 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 (U)ID for this class
    constructor_id = 0x810a9fec
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x6c4dd18c

    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.content_related = True

        self.game = game
        self.peer = get_input_peer(peer)
        self.msg_id = msg_id
        self.data = data

    def to_dict(self):
        return {
            'game': self.game,
            'peer': None if self.peer is None else self.peer.to_dict(),
            'msg_id': self.msg_id,
            'data': self.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 (attributes=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 TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
