"""File auto-generated by tglib TL generator. Do not edit manually."""
from ..tlobject import TLObject
from typing import Optional, List, Union
import os
import struct
from datetime import datetime


class Blocked(TLObject):
    """TL type: contacts.blocked"""
    CONSTRUCTOR_ID = 0x0ade1591
    SUBCLASS_OF_ID = 0xffba4f4f

    def __init__(self, blocked: List['TypePeerBlocked'], chats: List['TypeChat'], users: List['TypeUser']):
        self.blocked = blocked
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'Blocked',
            'blocked': self.blocked,
            'chats': self.chats,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.blocked)))
        for item in self.blocked:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_blocked = reader.read_int()
        _list_blocked = []
        for _ in range(_count_blocked):
            _item_blocked = reader.tgread_object()
            _list_blocked.append(_item_blocked)
        _args['blocked'] = _list_blocked
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class BlockedSlice(TLObject):
    """TL type: contacts.blockedSlice"""
    CONSTRUCTOR_ID = 0xe1664194
    SUBCLASS_OF_ID = 0xffba4f4f

    def __init__(self, count: int, blocked: List['TypePeerBlocked'], chats: List['TypeChat'], users: List['TypeUser']):
        self.count = count
        self.blocked = blocked
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'BlockedSlice',
            'count': self.count,
            'blocked': self.blocked,
            'chats': self.chats,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', self.count))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.blocked)))
        for item in self.blocked:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_count = reader.read_int()
        _args['count'] = _val_count
        reader.read_int(signed=False)  # skip vector id
        _count_blocked = reader.read_int()
        _list_blocked = []
        for _ in range(_count_blocked):
            _item_blocked = reader.tgread_object()
            _list_blocked.append(_item_blocked)
        _args['blocked'] = _list_blocked
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class ContactBirthdays(TLObject):
    """TL type: contacts.contactBirthdays"""
    CONSTRUCTOR_ID = 0x114ff30d
    SUBCLASS_OF_ID = 0x0e7aabff

    def __init__(self, contacts: List['TypeContactBirthday'], users: List['TypeUser']):
        self.contacts = contacts
        self.users = users

    def to_dict(self):
        return {
            '_': 'ContactBirthdays',
            'contacts': self.contacts,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.contacts)))
        for item in self.contacts:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_contacts = reader.read_int()
        _list_contacts = []
        for _ in range(_count_contacts):
            _item_contacts = reader.tgread_object()
            _list_contacts.append(_item_contacts)
        _args['contacts'] = _list_contacts
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class Contacts(TLObject):
    """TL type: contacts.contacts"""
    CONSTRUCTOR_ID = 0xeae87e42
    SUBCLASS_OF_ID = 0x38be25f6

    def __init__(self, contacts: List['TypeContact'], saved_count: int, users: List['TypeUser']):
        self.contacts = contacts
        self.saved_count = saved_count
        self.users = users

    def to_dict(self):
        return {
            '_': 'Contacts',
            'contacts': self.contacts,
            'saved_count': self.saved_count,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.contacts)))
        for item in self.contacts:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', self.saved_count))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_contacts = reader.read_int()
        _list_contacts = []
        for _ in range(_count_contacts):
            _item_contacts = reader.tgread_object()
            _list_contacts.append(_item_contacts)
        _args['contacts'] = _list_contacts
        _val_saved_count = reader.read_int()
        _args['saved_count'] = _val_saved_count
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class ContactsNotModified(TLObject):
    """TL type: contacts.contactsNotModified"""
    CONSTRUCTOR_ID = 0xb74ba9d2
    SUBCLASS_OF_ID = 0x38be25f6

    def __init__(self):
        pass

    def to_dict(self):
        return {
            '_': 'ContactsNotModified',
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        return cls()


class Found(TLObject):
    """TL type: contacts.found"""
    CONSTRUCTOR_ID = 0xb3134d9d
    SUBCLASS_OF_ID = 0x4386a2e3

    def __init__(self, my_results: List['TypePeer'], results: List['TypePeer'], chats: List['TypeChat'], users: List['TypeUser']):
        self.my_results = my_results
        self.results = results
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'Found',
            'my_results': self.my_results,
            'results': self.results,
            'chats': self.chats,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.my_results)))
        for item in self.my_results:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.results)))
        for item in self.results:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_my_results = reader.read_int()
        _list_my_results = []
        for _ in range(_count_my_results):
            _item_my_results = reader.tgread_object()
            _list_my_results.append(_item_my_results)
        _args['my_results'] = _list_my_results
        reader.read_int(signed=False)  # skip vector id
        _count_results = reader.read_int()
        _list_results = []
        for _ in range(_count_results):
            _item_results = reader.tgread_object()
            _list_results.append(_item_results)
        _args['results'] = _list_results
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class ImportedContacts(TLObject):
    """TL type: contacts.importedContacts"""
    CONSTRUCTOR_ID = 0x77d01c3b
    SUBCLASS_OF_ID = 0x8172ad93

    def __init__(self, imported: List['TypeImportedContact'], popular_invites: List['TypePopularContact'], retry_contacts: List[int], users: List['TypeUser']):
        self.imported = imported
        self.popular_invites = popular_invites
        self.retry_contacts = retry_contacts
        self.users = users

    def to_dict(self):
        return {
            '_': 'ImportedContacts',
            'imported': self.imported,
            'popular_invites': self.popular_invites,
            'retry_contacts': self.retry_contacts,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.imported)))
        for item in self.imported:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.popular_invites)))
        for item in self.popular_invites:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.retry_contacts)))
        for item in self.retry_contacts:
            buf.write(struct.pack('<q', self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_imported = reader.read_int()
        _list_imported = []
        for _ in range(_count_imported):
            _item_imported = reader.tgread_object()
            _list_imported.append(_item_imported)
        _args['imported'] = _list_imported
        reader.read_int(signed=False)  # skip vector id
        _count_popular_invites = reader.read_int()
        _list_popular_invites = []
        for _ in range(_count_popular_invites):
            _item_popular_invites = reader.tgread_object()
            _list_popular_invites.append(_item_popular_invites)
        _args['popular_invites'] = _list_popular_invites
        reader.read_int(signed=False)  # skip vector id
        _count_retry_contacts = reader.read_int()
        _list_retry_contacts = []
        for _ in range(_count_retry_contacts):
            _item_retry_contacts = reader.read_long()
            _list_retry_contacts.append(_item_retry_contacts)
        _args['retry_contacts'] = _list_retry_contacts
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class ResolvedPeer(TLObject):
    """TL type: contacts.resolvedPeer"""
    CONSTRUCTOR_ID = 0x7f077ad9
    SUBCLASS_OF_ID = 0xf065b3a8

    def __init__(self, peer: 'TypePeer', chats: List['TypeChat'], users: List['TypeUser']):
        self.peer = peer
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'ResolvedPeer',
            'peer': self.peer,
            'chats': self.chats,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(bytes(self.peer))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_peer = reader.tgread_object()
        _args['peer'] = _val_peer
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class SponsoredPeers(TLObject):
    """TL type: contacts.sponsoredPeers"""
    CONSTRUCTOR_ID = 0xeb032884
    SUBCLASS_OF_ID = 0xb45d5ccc

    def __init__(self, peers: List['TypeSponsoredPeer'], chats: List['TypeChat'], users: List['TypeUser']):
        self.peers = peers
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'SponsoredPeers',
            'peers': self.peers,
            'chats': self.chats,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.peers)))
        for item in self.peers:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_peers = reader.read_int()
        _list_peers = []
        for _ in range(_count_peers):
            _item_peers = reader.tgread_object()
            _list_peers.append(_item_peers)
        _args['peers'] = _list_peers
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class SponsoredPeersEmpty(TLObject):
    """TL type: contacts.sponsoredPeersEmpty"""
    CONSTRUCTOR_ID = 0xea32b4b1
    SUBCLASS_OF_ID = 0xb45d5ccc

    def __init__(self):
        pass

    def to_dict(self):
        return {
            '_': 'SponsoredPeersEmpty',
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        return cls()


class TopPeers(TLObject):
    """TL type: contacts.topPeers"""
    CONSTRUCTOR_ID = 0x70b772a8
    SUBCLASS_OF_ID = 0x9ee8bb88

    def __init__(self, categories: List['TypeTopPeerCategoryPeers'], chats: List['TypeChat'], users: List['TypeUser']):
        self.categories = categories
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'TopPeers',
            'categories': self.categories,
            'chats': self.chats,
            'users': self.users,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.categories)))
        for item in self.categories:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.chats)))
        for item in self.chats:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.users)))
        for item in self.users:
            buf.write(bytes(self.item))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        reader.read_int(signed=False)  # skip vector id
        _count_categories = reader.read_int()
        _list_categories = []
        for _ in range(_count_categories):
            _item_categories = reader.tgread_object()
            _list_categories.append(_item_categories)
        _args['categories'] = _list_categories
        reader.read_int(signed=False)  # skip vector id
        _count_chats = reader.read_int()
        _list_chats = []
        for _ in range(_count_chats):
            _item_chats = reader.tgread_object()
            _list_chats.append(_item_chats)
        _args['chats'] = _list_chats
        reader.read_int(signed=False)  # skip vector id
        _count_users = reader.read_int()
        _list_users = []
        for _ in range(_count_users):
            _item_users = reader.tgread_object()
            _list_users.append(_item_users)
        _args['users'] = _list_users
        return cls(**_args)


class TopPeersDisabled(TLObject):
    """TL type: contacts.topPeersDisabled"""
    CONSTRUCTOR_ID = 0xb52c939d
    SUBCLASS_OF_ID = 0x9ee8bb88

    def __init__(self):
        pass

    def to_dict(self):
        return {
            '_': 'TopPeersDisabled',
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        return cls()


class TopPeersNotModified(TLObject):
    """TL type: contacts.topPeersNotModified"""
    CONSTRUCTOR_ID = 0xde266ef5
    SUBCLASS_OF_ID = 0x9ee8bb88

    def __init__(self):
        pass

    def to_dict(self):
        return {
            '_': 'TopPeersNotModified',
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        return cls()

