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


class CheckChatlistInviteRequest(TLRequest):
    """TL type: chatlists.checkChatlistInvite"""
    CONSTRUCTOR_ID = 0x41c10fff
    SUBCLASS_OF_ID = 0x41720e75

    def __init__(self, slug: str):
        self.slug = slug

    def to_dict(self):
        return {
            '_': 'CheckChatlistInviteRequest',
            'slug': self.slug,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_slug = reader.tgread_string()
        _args['slug'] = _val_slug
        return cls(**_args)


class DeleteExportedInviteRequest(TLRequest):
    """TL type: chatlists.deleteExportedInvite"""
    CONSTRUCTOR_ID = 0x719c5c5e
    SUBCLASS_OF_ID = 0xf5b399ac

    def __init__(self, chatlist: 'TypeInputChatlist', slug: str):
        self.chatlist = chatlist
        self.slug = slug

    def to_dict(self):
        return {
            '_': 'DeleteExportedInviteRequest',
            'chatlist': self.chatlist,
            'slug': self.slug,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        _val_slug = reader.tgread_string()
        _args['slug'] = _val_slug
        return cls(**_args)


class EditExportedInviteRequest(TLRequest):
    """TL type: chatlists.editExportedInvite"""
    CONSTRUCTOR_ID = 0x653db63d
    SUBCLASS_OF_ID = 0x7711f8ff

    def __init__(self, chatlist: 'TypeInputChatlist', slug: str, title: Optional[str] = None, peers: Optional[List['TypeInputPeer']] = None):
        self.chatlist = chatlist
        self.slug = slug
        self.title = title
        self.peers = peers

    def to_dict(self):
        return {
            '_': 'EditExportedInviteRequest',
            'chatlist': self.chatlist,
            'slug': self.slug,
            'title': self.title,
            'peers': self.peers,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        flags = reader.read_int(signed=False)
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        _val_slug = reader.tgread_string()
        _args['slug'] = _val_slug
        if flags & (1 << 1):
            _val_title = reader.tgread_string()
            _args['title'] = _val_title
        else:
            _args['title'] = None
        if flags & (1 << 2):
            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
        else:
            _args['peers'] = None
        return cls(**_args)


class ExportChatlistInviteRequest(TLRequest):
    """TL type: chatlists.exportChatlistInvite"""
    CONSTRUCTOR_ID = 0x8472478e
    SUBCLASS_OF_ID = 0xc2694ee9

    def __init__(self, chatlist: 'TypeInputChatlist', title: str, peers: List['TypeInputPeer']):
        self.chatlist = chatlist
        self.title = title
        self.peers = peers

    def to_dict(self):
        return {
            '_': 'ExportChatlistInviteRequest',
            'chatlist': self.chatlist,
            'title': self.title,
            'peers': self.peers,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(bytes(self.chatlist))
        buf.write(TLObject.serialize_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))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        _val_title = reader.tgread_string()
        _args['title'] = _val_title
        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
        return cls(**_args)


class GetChatlistUpdatesRequest(TLRequest):
    """TL type: chatlists.getChatlistUpdates"""
    CONSTRUCTOR_ID = 0x89419521
    SUBCLASS_OF_ID = 0x7d1641ea

    def __init__(self, chatlist: 'TypeInputChatlist'):
        self.chatlist = chatlist

    def to_dict(self):
        return {
            '_': 'GetChatlistUpdatesRequest',
            'chatlist': self.chatlist,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        return cls(**_args)


class GetExportedInvitesRequest(TLRequest):
    """TL type: chatlists.getExportedInvites"""
    CONSTRUCTOR_ID = 0xce03da83
    SUBCLASS_OF_ID = 0xe6c209c0

    def __init__(self, chatlist: 'TypeInputChatlist'):
        self.chatlist = chatlist

    def to_dict(self):
        return {
            '_': 'GetExportedInvitesRequest',
            'chatlist': self.chatlist,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        return cls(**_args)


class GetLeaveChatlistSuggestionsRequest(TLRequest):
    """TL type: chatlists.getLeaveChatlistSuggestions"""
    CONSTRUCTOR_ID = 0xfdbcd714
    SUBCLASS_OF_ID = 0xb9945d7e

    def __init__(self, chatlist: 'TypeInputChatlist'):
        self.chatlist = chatlist

    def to_dict(self):
        return {
            '_': 'GetLeaveChatlistSuggestionsRequest',
            'chatlist': self.chatlist,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        return cls(**_args)


class HideChatlistUpdatesRequest(TLRequest):
    """TL type: chatlists.hideChatlistUpdates"""
    CONSTRUCTOR_ID = 0x66e486fb
    SUBCLASS_OF_ID = 0xf5b399ac

    def __init__(self, chatlist: 'TypeInputChatlist'):
        self.chatlist = chatlist

    def to_dict(self):
        return {
            '_': 'HideChatlistUpdatesRequest',
            'chatlist': self.chatlist,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        return cls(**_args)


class JoinChatlistInviteRequest(TLRequest):
    """TL type: chatlists.joinChatlistInvite"""
    CONSTRUCTOR_ID = 0xa6b1e39a
    SUBCLASS_OF_ID = 0x8af52aac

    def __init__(self, slug: str, peers: List['TypeInputPeer']):
        self.slug = slug
        self.peers = peers

    def to_dict(self):
        return {
            '_': 'JoinChatlistInviteRequest',
            'slug': self.slug,
            'peers': self.peers,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(TLObject.serialize_bytes(self.slug))
        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))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_slug = reader.tgread_string()
        _args['slug'] = _val_slug
        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
        return cls(**_args)


class JoinChatlistUpdatesRequest(TLRequest):
    """TL type: chatlists.joinChatlistUpdates"""
    CONSTRUCTOR_ID = 0xe089f8f5
    SUBCLASS_OF_ID = 0x8af52aac

    def __init__(self, chatlist: 'TypeInputChatlist', peers: List['TypeInputPeer']):
        self.chatlist = chatlist
        self.peers = peers

    def to_dict(self):
        return {
            '_': 'JoinChatlistUpdatesRequest',
            'chatlist': self.chatlist,
            'peers': self.peers,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        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
        return cls(**_args)


class LeaveChatlistRequest(TLRequest):
    """TL type: chatlists.leaveChatlist"""
    CONSTRUCTOR_ID = 0x74fae13a
    SUBCLASS_OF_ID = 0x8af52aac

    def __init__(self, chatlist: 'TypeInputChatlist', peers: List['TypeInputPeer']):
        self.chatlist = chatlist
        self.peers = peers

    def to_dict(self):
        return {
            '_': 'LeaveChatlistRequest',
            'chatlist': self.chatlist,
            'peers': self.peers,
        }

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

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_chatlist = reader.tgread_object()
        _args['chatlist'] = _val_chatlist
        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
        return cls(**_args)

