from telethon.tl.mtproto_request import MTProtoRequest


class PrivacyRules(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    account.privacyRules#554abb6f rules:Vector<PrivacyRule> users:Vector<User> = account.PrivacyRules"""

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

    def __init__(self, rules, users):
        """
        :param rules: Telegram type: «PrivacyRule». Must be a list.
        :param users: Telegram type: «User». Must be a list.
        """
        super().__init__()

        self.rules = rules
        self.users = users

    def on_send(self, writer):
        writer.write_int(PrivacyRules.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.rules))
        for rules_item in self.rules:
            rules_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 PrivacyRules(None, None)

    def on_response(self, reader):
        reader.read_int()  # Vector's constructor ID
        self.rules = []  # Initialize an empty list
        rules_len = reader.read_int()
        for _ in range(rules_len):
            rules_item = reader.tgread_object()
            self.rules.append(rules_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 'account.privacyRules#554abb6f rules:Vector<PrivacyRule> users:Vector<User> = account.PrivacyRules'

    def __str__(self):
        return '(account.privacyRules (ID: 0x554abb6f) = (rules={}, users={}))'.format(None if not self.rules else [str(_) for _ in self.rules], None if not self.users else [str(_) for _ in self.users])
