from telethon.tl.mtproto_request import MTProtoRequest


class Contacts(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    contacts.contacts#6f8b8cb2 contacts:Vector<Contact> users:Vector<User> = contacts.Contacts"""

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

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

        self.contacts = contacts
        self.users = users

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

    def on_response(self, reader):
        reader.read_int()  # Vector's constructor ID
        self.contacts = []  # Initialize an empty list
        contacts_len = reader.read_int()
        for _ in range(contacts_len):
            contacts_item = reader.tgread_object()
            self.contacts.append(contacts_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.contacts#6f8b8cb2 contacts:Vector<Contact> users:Vector<User> = contacts.Contacts'

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