from ....tl.mtproto_request import MTProtoRequest


class TopPeers(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    contacts.topPeers#70b772a8 categories:Vector<TopPeerCategoryPeers> chats:Vector<Chat> users:Vector<User> = contacts.TopPeers"""

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

    def __init__(self, categories, chats, users):
        """
        :param categories: Telegram type: "TopPeerCategoryPeers". Must be a list.
        :param chats: Telegram type: "Chat". Must be a list.
        :param users: Telegram type: "User". Must be a list.

        Constructor for contacts.TopPeers: Instance of either TopPeersNotModified, TopPeers.
        """
        super().__init__()

        self.categories = categories
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            'categories': [] if self.categories is None else [None if x is None else x.to_dict() for x in self.categories],
            'chats': [] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats],
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
        }

    def on_send(self, writer):
        writer.write_int(TopPeers.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.categories))
        for categories_item in self.categories:
            categories_item.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 (attributes=None)"""
        return TopPeers(None, None, None)

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

        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.topPeers#70b772a8 categories:Vector<TopPeerCategoryPeers> chats:Vector<Chat> users:Vector<User> = contacts.TopPeers'

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