from ....tl.mtproto_request import MTProtoRequest


class ResolvedPeer(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    contacts.resolvedPeer#7f077ad9 peer:Peer chats:Vector<Chat> users:Vector<User> = contacts.ResolvedPeer"""

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

    def __init__(self, peer, chats, users):
        """
        :param peer: Telegram type: «Peer».
        :param chats: Telegram type: «Chat». Must be a list.
        :param users: Telegram type: «User». Must be a list.

        Constructor for contacts.ResolvedPeer: Instance of ResolvedPeer.
        """
        super().__init__()

        self.peer = peer
        self.chats = chats
        self.users = users

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

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.users))
        for users_item in self.users:
            users_item.on_send(writer)

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

    def on_response(self, reader):
        self.peer = reader.tgread_object()
        reader.read_int()  # Vector's constructor ID
        self.chats = []  # Initialize an empty list
        chats_len = reader.read_int()
        for _ in range(chats_len):
            chats_item = reader.tgread_object()
            self.chats.append(chats_item)

        reader.read_int()  # Vector's constructor ID
        self.users = []  # Initialize an empty list
        users_len = reader.read_int()
        for _ in range(users_len):
            users_item = reader.tgread_object()
            self.users.append(users_item)

    def __repr__(self):
        return 'contacts.resolvedPeer#7f077ad9 peer:Peer chats:Vector<Chat> users:Vector<User> = contacts.ResolvedPeer'

    def __str__(self):
        return '(contacts.resolvedPeer (ID: 0x7f077ad9) = (peer={}, chats={}, users={}))'.format(str(self.peer), None if not self.chats else [str(_) for _ in self.chats], None if not self.users else [str(_) for _ in self.users])
