from telethon.tl.mtproto_request import MTProtoRequest


class UpdateBotInlineQuery(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    updateBotInlineQuery#54826690 flags:None query_id:long user_id:int query:string geo:flags.0?GeoPoint offset:string = Update"""

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

    def __init__(self, query_id, user_id, query, offset, geo=None):
        """
        :param query_id: Telegram type: «long».
        :param user_id: Telegram type: «int».
        :param query: Telegram type: «string».
        :param geo: Telegram type: «GeoPoint».
        :param offset: Telegram type: «string».
        """
        super().__init__()

        self.query_id = query_id
        self.user_id = user_id
        self.query = query
        self.geo = geo
        self.offset = offset

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

        writer.write_long(self.query_id)
        writer.write_int(self.user_id)
        writer.tgwrite_string(self.query)
        if self.geo:
            self.geo.on_send(writer)

        writer.tgwrite_string(self.offset)

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are None)"""
        return UpdateBotInlineQuery(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.query = reader.tgread_string()
        if (flags & (1 << 0)) != 0:
            self.geo = reader.tgread_object()

        self.offset = reader.tgread_string()

    def __repr__(self):
        return 'updateBotInlineQuery#54826690 flags:None query_id:long user_id:int query:string geo:flags.0?GeoPoint offset:string = Update'

    def __str__(self):
        return '(updateBotInlineQuery (ID: 0x54826690) = (query_id={}, user_id={}, query={}, geo={}, offset={}))'.format(str(self.query_id), str(self.user_id), str(self.query), str(self.geo), str(self.offset))
