from telethon.tl.mtproto_request import MTProtoRequest


class SetPrivacyRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    account.setPrivacy#c9f81ce8 key:InputPrivacyKey rules:Vector<InputPrivacyRule> = account.PrivacyRules"""

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

    def __init__(self, key, rules):
        """
        :param key: Telegram type: «InputPrivacyKey».
        :param rules: Telegram type: «InputPrivacyRule». Must be a list.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.key = key
        self.rules = rules

    def on_send(self, writer):
        writer.write_int(SetPrivacyRequest.constructor_id, signed=False)
        self.key.on_send(writer)
        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)

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

    def on_response(self, reader):
        self.result = reader.tgread_object()

    def __repr__(self):
        return 'account.setPrivacy#c9f81ce8 key:InputPrivacyKey rules:Vector<InputPrivacyRule> = account.PrivacyRules'

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