from telethon.tl.mtproto_request import MTProtoRequest


class SearchRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.search#d4569248 flags:None peer:InputPeer q:string filter:MessagesFilter min_date:date max_date:date offset:int max_id:int limit:int = messages.Messages"""

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

    def __init__(self, peer, q, filter, min_date, max_date, offset, max_id, limit):
        """
        :param peer: Telegram type: «InputPeer».
        :param q: Telegram type: «string».
        :param filter: Telegram type: «MessagesFilter».
        :param min_date: Telegram type: «date».
        :param max_date: Telegram type: «date».
        :param offset: Telegram type: «int».
        :param max_id: Telegram type: «int».
        :param limit: Telegram type: «int».
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.peer = peer
        self.q = q
        self.filter = filter
        self.min_date = min_date
        self.max_date = max_date
        self.offset = offset
        self.max_id = max_id
        self.limit = limit

    def on_send(self, writer):
        writer.write_int(SearchRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        writer.write_int(flags)

        self.peer.on_send(writer)
        writer.tgwrite_string(self.q)
        self.filter.on_send(writer)
        writer.tgwrite_date(self.min_date)
        writer.tgwrite_date(self.max_date)
        writer.write_int(self.offset)
        writer.write_int(self.max_id)
        writer.write_int(self.limit)

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

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

    def __repr__(self):
        return 'messages.search#d4569248 flags:None peer:InputPeer q:string filter:MessagesFilter min_date:date max_date:date offset:int max_id:int limit:int = messages.Messages'

    def __str__(self):
        return '(messages.search (ID: 0xd4569248) = (peer={}, q={}, filter={}, min_date={}, max_date={}, offset={}, max_id={}, limit={}))'.format(str(self.peer), str(self.q), str(self.filter), str(self.min_date), str(self.max_date), str(self.offset), str(self.max_id), str(self.limit))
