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


class GetMessagesViewsRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    messages.getMessagesViews#c4c8a55d peer:InputPeer id:Vector<int> increment:Bool = Vector<int>"""

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

    def __init__(self, peer, id, increment):
        """
        :param peer: Telegram type: "InputPeer".
        :param id: Telegram type: "int". Must be a list.
        :param increment: Telegram type: "Bool".

        :returns Vector<int>: This type has no constructors.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.peer = get_input_peer(peer)
        self.id = id
        self.increment = increment

    def to_dict(self):
        return {
            'peer': None if self.peer is None else self.peer.to_dict(),
            'id': [] if self.id is None else self.id[:],
            'increment': self.increment,
        }

    def on_send(self, writer):
        writer.write_int(GetMessagesViewsRequest.constructor_id, signed=False)
        self.peer.on_send(writer)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.id))
        for id_item in self.id:
            writer.write_int(id_item)

        writer.tgwrite_bool(self.increment)

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

    def on_response(self, reader):
        reader.read_int()  # Vector id
        count = reader.read_int()
        self.result = [reader.read_int() for _ in range(count)]

    def __repr__(self):
        return 'messages.getMessagesViews#c4c8a55d peer:InputPeer id:Vector<int> increment:Bool = Vector<int>'

    def __str__(self):
        return '(messages.getMessagesViews (ID: 0xc4c8a55d) = (peer={}, id={}, increment={}))'.format(str(self.peer), None if not self.id else [str(_) for _ in self.id], str(self.increment))
