from ....tl.tlobject import TLObject


class ImportedContacts(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    contacts.importedContacts#77d01c3b imported:Vector<ImportedContact> popular_invites:Vector<PopularContact> retry_contacts:Vector<long> users:Vector<User> = contacts.ImportedContacts"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0x77d01c3b
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x8172ad93

    def __init__(self, imported, popular_invites, retry_contacts, users):
        """
        :param imported: Telegram type: "ImportedContact". Must be a list.
        :param popular_invites: Telegram type: "PopularContact". Must be a list.
        :param retry_contacts: Telegram type: "long". Must be a list.
        :param users: Telegram type: "User". Must be a list.

        Constructor for contacts.ImportedContacts: Instance of ImportedContacts.
        """
        super().__init__()

        self.imported = imported
        self.popular_invites = popular_invites
        self.retry_contacts = retry_contacts
        self.users = users

    def to_dict(self):
        return {
            'imported': [] if self.imported is None else [None if x is None else x.to_dict() for x in self.imported],
            'popular_invites': [] if self.popular_invites is None else [None if x is None else x.to_dict() for x in self.popular_invites],
            'retry_contacts': [] if self.retry_contacts is None else self.retry_contacts[:],
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
        }

    def on_send(self, writer):
        writer.write_int(ImportedContacts.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.imported))
        for _x in self.imported:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.popular_invites))
        for _x in self.popular_invites:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.retry_contacts))
        for _x in self.retry_contacts:
            writer.write_long(_x)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.users))
        for _x in self.users:
            _x.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return ImportedContacts(None, None, None, None)

    def on_response(self, reader):
        reader.read_int()  # Vector's constructor ID
        self.imported = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.imported.append(_x)

        reader.read_int()  # Vector's constructor ID
        self.popular_invites = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.popular_invites.append(_x)

        reader.read_int()  # Vector's constructor ID
        self.retry_contacts = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.read_long()
            self.retry_contacts.append(_x)

        reader.read_int()  # Vector's constructor ID
        self.users = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.users.append(_x)

    def __repr__(self):
        return 'contacts.importedContacts#77d01c3b imported:Vector<ImportedContact> popular_invites:Vector<PopularContact> retry_contacts:Vector<long> users:Vector<User> = contacts.ImportedContacts'

    def __str__(self):
        return TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
