from ....tl.mtproto_request import MTProtoRequest
from ....utils import get_input_peer


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

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

    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 = get_input_peer(offset_peer)
        self.offset_id = offset_id
        self.limit = limit

    def to_dict(self):
        return {
            'q': self.q,
            'offset_date': self.offset_date,
            'offset_peer': None if self.offset_peer is None else self.offset_peer.to_dict(),
            'offset_id': self.offset_id,
            'limit': self.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 (attributes=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:int 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))
