"""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 ChatlistInvite(TLObject):
    """TL type: chatlists.chatlistInvite"""
    CONSTRUCTOR_ID = 0xf10ece2f
    SUBCLASS_OF_ID = 0x41720e75

    def __init__(self, title: 'TypeTextWithEntities', peers: List['TypePeer'], chats: List['TypeChat'], users: List['TypeUser'], title_noanimate: Optional[bool] = None, emoticon: Optional[str] = None):
        self.title = title
        self.peers = peers
        self.chats = chats
        self.users = users
        self.title_noanimate = title_noanimate
        self.emoticon = emoticon

    def to_dict(self):
        return {
            '_': 'ChatlistInvite',
            'title': self.title,
            'peers': self.peers,
            'chats': self.chats,
            'users': self.users,
            'title_noanimate': self.title_noanimate,
            'emoticon': self.emoticon,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        flags = 0
        if self.title_noanimate:
            flags |= (1 << 1)
        if self.emoticon is not None:
            flags |= (1 << 0)
        buf.write(struct.pack('<I', flags))
        buf.write(bytes(self.title))
        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))
        if self.emoticon is not None:
            buf.write(TLObject.serialize_bytes(self.emoticon))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _args['title_noanimate'] = bool(flags & (1 << 1))
        _val_title = reader.tgread_object()
        _args['title'] = _val_title
        if flags & (1 << 0):
            _val_emoticon = reader.tgread_string()
            _args['emoticon'] = _val_emoticon
        else:
            _args['emoticon'] = None
        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 ChatlistInviteAlready(TLObject):
    """TL type: chatlists.chatlistInviteAlready"""
    CONSTRUCTOR_ID = 0xfa87f659
    SUBCLASS_OF_ID = 0x41720e75

    def __init__(self, filter_id: int, missing_peers: List['TypePeer'], already_peers: List['TypePeer'], chats: List['TypeChat'], users: List['TypeUser']):
        self.filter_id = filter_id
        self.missing_peers = missing_peers
        self.already_peers = already_peers
        self.chats = chats
        self.users = users

    def to_dict(self):
        return {
            '_': 'ChatlistInviteAlready',
            'filter_id': self.filter_id,
            'missing_peers': self.missing_peers,
            'already_peers': self.already_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', self.filter_id))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.missing_peers)))
        for item in self.missing_peers:
            buf.write(bytes(self.item))
        buf.write(struct.pack('<i', 0x1cb5c415))  # vector id
        buf.write(struct.pack('<i', len(self.already_peers)))
        for item in self.already_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 = {}
        _val_filter_id = reader.read_int()
        _args['filter_id'] = _val_filter_id
        reader.read_int(signed=False)  # skip vector id
        _count_missing_peers = reader.read_int()
        _list_missing_peers = []
        for _ in range(_count_missing_peers):
            _item_missing_peers = reader.tgread_object()
            _list_missing_peers.append(_item_missing_peers)
        _args['missing_peers'] = _list_missing_peers
        reader.read_int(signed=False)  # skip vector id
        _count_already_peers = reader.read_int()
        _list_already_peers = []
        for _ in range(_count_already_peers):
            _item_already_peers = reader.tgread_object()
            _list_already_peers.append(_item_already_peers)
        _args['already_peers'] = _list_already_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 ChatlistUpdates(TLObject):
    """TL type: chatlists.chatlistUpdates"""
    CONSTRUCTOR_ID = 0x93bd878d
    SUBCLASS_OF_ID = 0x7d1641ea

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

    def to_dict(self):
        return {
            '_': 'ChatlistUpdates',
            'missing_peers': self.missing_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.missing_peers)))
        for item in self.missing_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_missing_peers = reader.read_int()
        _list_missing_peers = []
        for _ in range(_count_missing_peers):
            _item_missing_peers = reader.tgread_object()
            _list_missing_peers.append(_item_missing_peers)
        _args['missing_peers'] = _list_missing_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 ExportedChatlistInvite(TLObject):
    """TL type: chatlists.exportedChatlistInvite"""
    CONSTRUCTOR_ID = 0x10e6e3a6
    SUBCLASS_OF_ID = 0xc2694ee9

    def __init__(self, filter: 'TypeDialogFilter', invite: 'TypeExportedChatlistInvite'):
        self.filter = filter
        self.invite = invite

    def to_dict(self):
        return {
            '_': 'ExportedChatlistInvite',
            'filter': self.filter,
            'invite': self.invite,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_filter = reader.tgread_object()
        _args['filter'] = _val_filter
        _val_invite = reader.tgread_object()
        _args['invite'] = _val_invite
        return cls(**_args)


class ExportedInvites(TLObject):
    """TL type: chatlists.exportedInvites"""
    CONSTRUCTOR_ID = 0x10ab6dc7
    SUBCLASS_OF_ID = 0xe6c209c0

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

    def to_dict(self):
        return {
            '_': 'ExportedInvites',
            'invites': self.invites,
            '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.invites)))
        for item in self.invites:
            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_invites = reader.read_int()
        _list_invites = []
        for _ in range(_count_invites):
            _item_invites = reader.tgread_object()
            _list_invites.append(_item_invites)
        _args['invites'] = _list_invites
        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)

