from ...tl.tlobject import TLObject


class UpdateInlineBotCallbackQuery(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    updateInlineBotCallbackQuery#f9d27a5a flags:# query_id:long user_id:int msg_id:InputBotInlineMessageID chat_instance:long data:flags.0?bytes game_short_name:flags.1?string = Update"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0xf9d27a5a
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x9f89304e

    def __init__(self, query_id, user_id, msg_id, chat_instance, data=None, game_short_name=None):
        """
        :param query_id: Telegram type: "long".
        :param user_id: Telegram type: "int".
        :param msg_id: Telegram type: "InputBotInlineMessageID".
        :param chat_instance: Telegram type: "long".
        :param data: Telegram type: "bytes".
        :param game_short_name: Telegram type: "string".

        Constructor for Update: Instance of either UpdateNewMessage, UpdateMessageID, UpdateDeleteMessages, UpdateUserTyping, UpdateChatUserTyping, UpdateChatParticipants, UpdateUserStatus, UpdateUserName, UpdateUserPhoto, UpdateContactRegistered, UpdateContactLink, UpdateNewEncryptedMessage, UpdateEncryptedChatTyping, UpdateEncryption, UpdateEncryptedMessagesRead, UpdateChatParticipantAdd, UpdateChatParticipantDelete, UpdateDcOptions, UpdateUserBlocked, UpdateNotifySettings, UpdateServiceNotification, UpdatePrivacy, UpdateUserPhone, UpdateReadHistoryInbox, UpdateReadHistoryOutbox, UpdateWebPage, UpdateReadMessagesContents, UpdateChannelTooLong, UpdateChannel, UpdateNewChannelMessage, UpdateReadChannelInbox, UpdateDeleteChannelMessages, UpdateChannelMessageViews, UpdateChatAdmins, UpdateChatParticipantAdmin, UpdateNewStickerSet, UpdateStickerSetsOrder, UpdateStickerSets, UpdateSavedGifs, UpdateBotInlineQuery, UpdateBotInlineSend, UpdateEditChannelMessage, UpdateChannelPinnedMessage, UpdateBotCallbackQuery, UpdateEditMessage, UpdateInlineBotCallbackQuery, UpdateReadChannelOutbox, UpdateDraftMessage, UpdateReadFeaturedStickers, UpdateRecentStickers, UpdateConfig, UpdatePtsChanged, UpdateChannelWebPage, UpdateDialogPinned, UpdatePinnedDialogs, UpdateBotWebhookJSON, UpdateBotWebhookJSONQuery, UpdateBotShippingQuery, UpdateBotPrecheckoutQuery, UpdatePhoneCall, UpdateLangPackTooLong, UpdateLangPack.
        """
        super().__init__()

        self.query_id = query_id
        self.user_id = user_id
        self.msg_id = msg_id
        self.chat_instance = chat_instance
        self.data = data
        self.game_short_name = game_short_name

    def to_dict(self):
        return {
            'query_id': self.query_id,
            'user_id': self.user_id,
            'msg_id': None if self.msg_id is None else self.msg_id.to_dict(),
            'chat_instance': self.chat_instance,
            'data': self.data,
            'game_short_name': self.game_short_name,
        }

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

        writer.write_long(self.query_id)
        writer.write_int(self.user_id)
        self.msg_id.on_send(writer)
        writer.write_long(self.chat_instance)
        if self.data:
            writer.tgwrite_bytes(self.data)

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

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return UpdateInlineBotCallbackQuery(None, None, None, None, None, None)

    def on_response(self, reader):
        flags = reader.read_int()

        self.query_id = reader.read_long()
        self.user_id = reader.read_int()
        self.msg_id = reader.tgread_object()
        self.chat_instance = reader.read_long()
        if (flags & (1 << 0)) != 0:
            self.data = reader.tgread_bytes()

        if (flags & (1 << 1)) != 0:
            self.game_short_name = reader.tgread_string()

    def __repr__(self):
        return 'updateInlineBotCallbackQuery#f9d27a5a flags:# query_id:long user_id:int msg_id:InputBotInlineMessageID chat_instance:long data:flags.0?bytes game_short_name:flags.1?string = Update'

    def __str__(self):
        return TLObject.pretty_format(self)

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