from ...tl.mtproto_request import MTProtoRequest


class TopPeerCategoryPeers(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    topPeerCategoryPeers#fb834291 category:TopPeerCategory count:int peers:Vector<TopPeer> = TopPeerCategoryPeers"""

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

    def __init__(self, category, count, peers):
        """
        :param category: Telegram type: «TopPeerCategory».
        :param count: Telegram type: «int».
        :param peers: Telegram type: «TopPeer». Must be a list.

        Constructor for TopPeerCategoryPeers: Instance of TopPeerCategoryPeers.
        """
        super().__init__()

        self.category = category
        self.count = count
        self.peers = peers

    def on_send(self, writer):
        writer.write_int(TopPeerCategoryPeers.constructor_id, signed=False)
        self.category.on_send(writer)
        writer.write_int(self.count)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.peers))
        for peers_item in self.peers:
            peers_item.on_send(writer)

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

    def on_response(self, reader):
        self.category = reader.tgread_object()
        self.count = reader.read_int()
        reader.read_int()  # Vector's constructor ID
        self.peers = []  # Initialize an empty list
        peers_len = reader.read_int()
        for _ in range(peers_len):
            peers_item = reader.tgread_object()
            self.peers.append(peers_item)

    def __repr__(self):
        return 'topPeerCategoryPeers#fb834291 category:TopPeerCategory count:int peers:Vector<TopPeer> = TopPeerCategoryPeers'

    def __str__(self):
        return '(topPeerCategoryPeers (ID: 0xfb834291) = (category={}, count={}, peers={}))'.format(str(self.category), str(self.count), None if not self.peers else [str(_) for _ in self.peers])
