from telethon.tl.mtproto_request import MTProtoRequest


class BlockedSlice(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    contacts.blockedSlice#900802a1 count:int blocked:Vector<ContactBlocked> users:Vector<User> = contacts.Blocked"""

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

    def __init__(self, count, blocked, users):
        """
        :param count: Telegram type: «int».
        :param blocked: Telegram type: «ContactBlocked». Must be a list.
        :param users: Telegram type: «User». Must be a list.
        """
        super().__init__()

        self.count = count
        self.blocked = blocked
        self.users = users

    def on_send(self, writer):
        writer.write_int(BlockedSlice.constructor_id, signed=False)
        writer.write_int(self.count)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.blocked))
        for blocked_item in self.blocked:
            blocked_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 BlockedSlice(None, None, None)

    def on_response(self, reader):
        self.count = reader.read_int()
        reader.read_int()  # Vector's constructor ID
        self.blocked = []  # Initialize an empty list
        blocked_len = reader.read_int()
        for _ in range(blocked_len):
            blocked_item = reader.tgread_object()
            self.blocked.append(blocked_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.blockedSlice#900802a1 count:int blocked:Vector<ContactBlocked> users:Vector<User> = contacts.Blocked'

    def __str__(self):
        return '(contacts.blockedSlice (ID: 0x900802a1) = (count={}, blocked={}, users={}))'.format(str(self.count), None if not self.blocked else [str(_) for _ in self.blocked], None if not self.users else [str(_) for _ in self.users])
