from ....tl.mtproto_request import MTProtoRequest


class SearchGlobalRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.searchGlobal#9e3cacb0 q:string offset_date:date offset_peer:InputPeer offset_id:int limit:int = messages.Messages"""

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

    def __init__(self, q, offset_date, offset_peer, offset_id, limit):
        """
        :param q: Telegram type: «string».
        :param offset_date: Telegram type: «date».
        :param offset_peer: Telegram type: «InputPeer».
        :param offset_id: Telegram type: «int».
        :param limit: Telegram type: «int».

        :returns messages.Messages: Instance of either Messages, MessagesSlice, ChannelMessages.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.q = q
        self.offset_date = offset_date
        self.offset_peer = offset_peer
        self.offset_id = offset_id
        self.limit = limit

    def on_send(self, writer):
        writer.write_int(SearchGlobalRequest.constructor_id, signed=False)
        writer.tgwrite_string(self.q)
        writer.tgwrite_date(self.offset_date)
        self.offset_peer.on_send(writer)
        writer.write_int(self.offset_id)
        writer.write_int(self.limit)

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

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

    def __repr__(self):
        return 'messages.searchGlobal#9e3cacb0 q:string offset_date:date offset_peer:InputPeer offset_id:int limit:int = messages.Messages'

    def __str__(self):
        return '(messages.searchGlobal (ID: 0x9e3cacb0) = (q={}, offset_date={}, offset_peer={}, offset_id={}, limit={}))'.format(str(self.q), str(self.offset_date), str(self.offset_peer), str(self.offset_id), str(self.limit))
