from ....tl.tlobject import TLObject
from ....utils import get_input_peer


class GetHistoryRequest(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    messages.getHistory#afa92846 peer:InputPeer offset_id:int offset_date:int add_offset:int limit:int max_id:int min_id:int = messages.Messages"""

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

    def __init__(self, peer, offset_id, offset_date, add_offset, limit, max_id, min_id):
        """
        :param peer: Telegram type: "InputPeer".
        :param offset_id: Telegram type: "int".
        :param offset_date: Telegram type: "date".
        :param add_offset: Telegram type: "int".
        :param limit: Telegram type: "int".
        :param max_id: Telegram type: "int".
        :param min_id: Telegram type: "int".

        :returns messages.Messages: Instance of either Messages, MessagesSlice, ChannelMessages.
        """
        super().__init__()
        self.result = None
        self.content_related = True

        self.peer = get_input_peer(peer)
        self.offset_id = offset_id
        self.offset_date = offset_date
        self.add_offset = add_offset
        self.limit = limit
        self.max_id = max_id
        self.min_id = min_id

    def to_dict(self):
        return {
            'peer': None if self.peer is None else self.peer.to_dict(),
            'offset_id': self.offset_id,
            'offset_date': self.offset_date,
            'add_offset': self.add_offset,
            'limit': self.limit,
            'max_id': self.max_id,
            'min_id': self.min_id,
        }

    def on_send(self, writer):
        writer.write_int(GetHistoryRequest.constructor_id, signed=False)
        self.peer.on_send(writer)
        writer.write_int(self.offset_id)
        writer.tgwrite_date(self.offset_date)
        writer.write_int(self.add_offset)
        writer.write_int(self.limit)
        writer.write_int(self.max_id)
        writer.write_int(self.min_id)

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

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

    def __repr__(self):
        return 'messages.getHistory#afa92846 peer:InputPeer offset_id:int offset_date:int add_offset:int limit:int max_id:int min_id:int = messages.Messages'

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

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