"""File generated by TLObjects' generator. All changes will be ERASED"""
from .._misc.tlobject import TLObject, TLRequest
from . import fn
from typing import Optional, List, Union, TYPE_CHECKING
import os
import struct
import dataclasses
from datetime import datetime
if TYPE_CHECKING:
    from . import TypeChat, TypeDialog, TypeEncryptedMessage, TypeMessage, TypeUpdate, TypeUser
    from ..updates import TypeState



@dataclasses.dataclass(init=False, frozen=True)
class ChannelDifference(TLObject):
    """
    Constructor for updates.ChannelDifference: Instance of either ChannelDifferenceEmpty, ChannelDifferenceTooLong, ChannelDifference.
    """
    __slots__ = ('pts', 'new_messages', 'other_updates', 'chats', 'users', 'final', 'timeout',)
    CONSTRUCTOR_ID = 0x2064674e
    SUBCLASS_OF_ID = 0x29896f5d

    pts: int
    new_messages: List['TypeMessage']
    other_updates: List['TypeUpdate']
    chats: List['TypeChat']
    users: List['TypeUser']
    final: Optional[bool]
    timeout: Optional[int]
    def __init__(self, pts: int, new_messages: List['TypeMessage'], other_updates: List['TypeUpdate'], chats: List['TypeChat'], users: List['TypeUser'], final: Optional[bool]=None, timeout: Optional[int]=None):
        object.__setattr__(self, 'pts', pts)
        object.__setattr__(self, 'new_messages', new_messages)
        object.__setattr__(self, 'other_updates', other_updates)
        object.__setattr__(self, 'chats', chats)
        object.__setattr__(self, 'users', users)
        object.__setattr__(self, 'final', final)
        object.__setattr__(self, 'timeout', timeout)

    def _bytes(self):
        return b''.join((
            b'Ngd ',
            struct.pack('<I', (0 if self.final is None or self.final is False else 1) | (0 if self.timeout is None or self.timeout is False else 2)),
            struct.pack('<i', self.pts),
            b'' if self.timeout is None or self.timeout is False else (struct.pack('<i', self.timeout)),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.new_messages)),b''.join(x._bytes() for x in self.new_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.other_updates)),b''.join(x._bytes() for x in self.other_updates),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.chats)),b''.join(x._bytes() for x in self.chats),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.users)),b''.join(x._bytes() for x in self.users),
        ))

    @classmethod
    def _from_reader(cls, reader):
        flags = reader.read_int()

        _final = bool(flags & 1)
        _pts = reader.read_int()
        if flags & 2:
            _timeout = reader.read_int()
        else:
            _timeout = None
        reader.read_int()
        _new_messages = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _new_messages.append(_x)

        reader.read_int()
        _other_updates = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _other_updates.append(_x)

        reader.read_int()
        _chats = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _chats.append(_x)

        reader.read_int()
        _users = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _users.append(_x)

        return cls(pts=_pts, new_messages=_new_messages, other_updates=_other_updates, chats=_chats, users=_users, final=_final, timeout=_timeout)


@dataclasses.dataclass(init=False, frozen=True)
class ChannelDifferenceEmpty(TLObject):
    """
    Constructor for updates.ChannelDifference: Instance of either ChannelDifferenceEmpty, ChannelDifferenceTooLong, ChannelDifference.
    """
    __slots__ = ('pts', 'final', 'timeout',)
    CONSTRUCTOR_ID = 0x3e11affb
    SUBCLASS_OF_ID = 0x29896f5d

    pts: int
    final: Optional[bool]
    timeout: Optional[int]
    def __init__(self, pts: int, final: Optional[bool]=None, timeout: Optional[int]=None):
        object.__setattr__(self, 'pts', pts)
        object.__setattr__(self, 'final', final)
        object.__setattr__(self, 'timeout', timeout)

    def _bytes(self):
        return b''.join((
            b'\xfb\xaf\x11>',
            struct.pack('<I', (0 if self.final is None or self.final is False else 1) | (0 if self.timeout is None or self.timeout is False else 2)),
            struct.pack('<i', self.pts),
            b'' if self.timeout is None or self.timeout is False else (struct.pack('<i', self.timeout)),
        ))

    @classmethod
    def _from_reader(cls, reader):
        flags = reader.read_int()

        _final = bool(flags & 1)
        _pts = reader.read_int()
        if flags & 2:
            _timeout = reader.read_int()
        else:
            _timeout = None
        return cls(pts=_pts, final=_final, timeout=_timeout)


@dataclasses.dataclass(init=False, frozen=True)
class ChannelDifferenceTooLong(TLObject):
    """
    Constructor for updates.ChannelDifference: Instance of either ChannelDifferenceEmpty, ChannelDifferenceTooLong, ChannelDifference.
    """
    __slots__ = ('dialog', 'messages', 'chats', 'users', 'final', 'timeout',)
    CONSTRUCTOR_ID = 0xa4bcc6fe
    SUBCLASS_OF_ID = 0x29896f5d

    dialog: 'TypeDialog'
    messages: List['TypeMessage']
    chats: List['TypeChat']
    users: List['TypeUser']
    final: Optional[bool]
    timeout: Optional[int]
    def __init__(self, dialog: 'TypeDialog', messages: List['TypeMessage'], chats: List['TypeChat'], users: List['TypeUser'], final: Optional[bool]=None, timeout: Optional[int]=None):
        object.__setattr__(self, 'dialog', dialog)
        object.__setattr__(self, 'messages', messages)
        object.__setattr__(self, 'chats', chats)
        object.__setattr__(self, 'users', users)
        object.__setattr__(self, 'final', final)
        object.__setattr__(self, 'timeout', timeout)

    def _bytes(self):
        return b''.join((
            b'\xfe\xc6\xbc\xa4',
            struct.pack('<I', (0 if self.final is None or self.final is False else 1) | (0 if self.timeout is None or self.timeout is False else 2)),
            b'' if self.timeout is None or self.timeout is False else (struct.pack('<i', self.timeout)),
            self.dialog._bytes(),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.messages)),b''.join(x._bytes() for x in self.messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.chats)),b''.join(x._bytes() for x in self.chats),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.users)),b''.join(x._bytes() for x in self.users),
        ))

    @classmethod
    def _from_reader(cls, reader):
        flags = reader.read_int()

        _final = bool(flags & 1)
        if flags & 2:
            _timeout = reader.read_int()
        else:
            _timeout = None
        _dialog = reader.tgread_object()
        reader.read_int()
        _messages = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _messages.append(_x)

        reader.read_int()
        _chats = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _chats.append(_x)

        reader.read_int()
        _users = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _users.append(_x)

        return cls(dialog=_dialog, messages=_messages, chats=_chats, users=_users, final=_final, timeout=_timeout)


@dataclasses.dataclass(init=False, frozen=True)
class Difference(TLObject):
    """
    Constructor for updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
    """
    __slots__ = ('new_messages', 'new_encrypted_messages', 'other_updates', 'chats', 'users', 'state',)
    CONSTRUCTOR_ID = 0xf49ca0
    SUBCLASS_OF_ID = 0x20482874

    new_messages: List['TypeMessage']
    new_encrypted_messages: List['TypeEncryptedMessage']
    other_updates: List['TypeUpdate']
    chats: List['TypeChat']
    users: List['TypeUser']
    state: 'TypeState'
    def __init__(self, new_messages: List['TypeMessage'], new_encrypted_messages: List['TypeEncryptedMessage'], other_updates: List['TypeUpdate'], chats: List['TypeChat'], users: List['TypeUser'], state: 'TypeState'):
        object.__setattr__(self, 'new_messages', new_messages)
        object.__setattr__(self, 'new_encrypted_messages', new_encrypted_messages)
        object.__setattr__(self, 'other_updates', other_updates)
        object.__setattr__(self, 'chats', chats)
        object.__setattr__(self, 'users', users)
        object.__setattr__(self, 'state', state)

    def _bytes(self):
        return b''.join((
            b'\xa0\x9c\xf4\x00',
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.new_messages)),b''.join(x._bytes() for x in self.new_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.new_encrypted_messages)),b''.join(x._bytes() for x in self.new_encrypted_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.other_updates)),b''.join(x._bytes() for x in self.other_updates),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.chats)),b''.join(x._bytes() for x in self.chats),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.users)),b''.join(x._bytes() for x in self.users),
            self.state._bytes(),
        ))

    @classmethod
    def _from_reader(cls, reader):
        reader.read_int()
        _new_messages = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _new_messages.append(_x)

        reader.read_int()
        _new_encrypted_messages = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _new_encrypted_messages.append(_x)

        reader.read_int()
        _other_updates = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _other_updates.append(_x)

        reader.read_int()
        _chats = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _chats.append(_x)

        reader.read_int()
        _users = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _users.append(_x)

        _state = reader.tgread_object()
        return cls(new_messages=_new_messages, new_encrypted_messages=_new_encrypted_messages, other_updates=_other_updates, chats=_chats, users=_users, state=_state)


@dataclasses.dataclass(init=False, frozen=True)
class DifferenceEmpty(TLObject):
    """
    Constructor for updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
    """
    __slots__ = ('date', 'seq',)
    CONSTRUCTOR_ID = 0x5d75a138
    SUBCLASS_OF_ID = 0x20482874

    date: Optional[datetime]
    seq: int
    def __init__(self, date: Optional[datetime], seq: int):
        object.__setattr__(self, 'date', date)
        object.__setattr__(self, 'seq', seq)

    def _bytes(self):
        return b''.join((
            b'8\xa1u]',
            self._serialize_datetime(self.date),
            struct.pack('<i', self.seq),
        ))

    @classmethod
    def _from_reader(cls, reader):
        _date = reader.tgread_date()
        _seq = reader.read_int()
        return cls(date=_date, seq=_seq)


@dataclasses.dataclass(init=False, frozen=True)
class DifferenceSlice(TLObject):
    """
    Constructor for updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
    """
    __slots__ = ('new_messages', 'new_encrypted_messages', 'other_updates', 'chats', 'users', 'intermediate_state',)
    CONSTRUCTOR_ID = 0xa8fb1981
    SUBCLASS_OF_ID = 0x20482874

    new_messages: List['TypeMessage']
    new_encrypted_messages: List['TypeEncryptedMessage']
    other_updates: List['TypeUpdate']
    chats: List['TypeChat']
    users: List['TypeUser']
    intermediate_state: 'TypeState'
    def __init__(self, new_messages: List['TypeMessage'], new_encrypted_messages: List['TypeEncryptedMessage'], other_updates: List['TypeUpdate'], chats: List['TypeChat'], users: List['TypeUser'], intermediate_state: 'TypeState'):
        object.__setattr__(self, 'new_messages', new_messages)
        object.__setattr__(self, 'new_encrypted_messages', new_encrypted_messages)
        object.__setattr__(self, 'other_updates', other_updates)
        object.__setattr__(self, 'chats', chats)
        object.__setattr__(self, 'users', users)
        object.__setattr__(self, 'intermediate_state', intermediate_state)

    def _bytes(self):
        return b''.join((
            b'\x81\x19\xfb\xa8',
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.new_messages)),b''.join(x._bytes() for x in self.new_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.new_encrypted_messages)),b''.join(x._bytes() for x in self.new_encrypted_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.other_updates)),b''.join(x._bytes() for x in self.other_updates),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.chats)),b''.join(x._bytes() for x in self.chats),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.users)),b''.join(x._bytes() for x in self.users),
            self.intermediate_state._bytes(),
        ))

    @classmethod
    def _from_reader(cls, reader):
        reader.read_int()
        _new_messages = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _new_messages.append(_x)

        reader.read_int()
        _new_encrypted_messages = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _new_encrypted_messages.append(_x)

        reader.read_int()
        _other_updates = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _other_updates.append(_x)

        reader.read_int()
        _chats = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _chats.append(_x)

        reader.read_int()
        _users = []
        for _ in range(reader.read_int()):
            _x = reader.tgread_object()
            _users.append(_x)

        _intermediate_state = reader.tgread_object()
        return cls(new_messages=_new_messages, new_encrypted_messages=_new_encrypted_messages, other_updates=_other_updates, chats=_chats, users=_users, intermediate_state=_intermediate_state)


@dataclasses.dataclass(init=False, frozen=True)
class DifferenceTooLong(TLObject):
    """
    Constructor for updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
    """
    __slots__ = ('pts',)
    CONSTRUCTOR_ID = 0x4afe8f6d
    SUBCLASS_OF_ID = 0x20482874

    pts: int
    def __init__(self, pts: int):
        object.__setattr__(self, 'pts', pts)

    def _bytes(self):
        return b''.join((
            b'm\x8f\xfeJ',
            struct.pack('<i', self.pts),
        ))

    @classmethod
    def _from_reader(cls, reader):
        _pts = reader.read_int()
        return cls(pts=_pts)


@dataclasses.dataclass(init=False, frozen=True)
class State(TLObject):
    """
    Constructor for updates.State: Instance of State.
    """
    __slots__ = ('pts', 'qts', 'date', 'seq', 'unread_count',)
    CONSTRUCTOR_ID = 0xa56c2a3e
    SUBCLASS_OF_ID = 0x23df1a01

    pts: int
    qts: int
    date: Optional[datetime]
    seq: int
    unread_count: int
    def __init__(self, pts: int, qts: int, date: Optional[datetime], seq: int, unread_count: int):
        object.__setattr__(self, 'pts', pts)
        object.__setattr__(self, 'qts', qts)
        object.__setattr__(self, 'date', date)
        object.__setattr__(self, 'seq', seq)
        object.__setattr__(self, 'unread_count', unread_count)

    def _bytes(self):
        return b''.join((
            b'>*l\xa5',
            struct.pack('<i', self.pts),
            struct.pack('<i', self.qts),
            self._serialize_datetime(self.date),
            struct.pack('<i', self.seq),
            struct.pack('<i', self.unread_count),
        ))

    @classmethod
    def _from_reader(cls, reader):
        _pts = reader.read_int()
        _qts = reader.read_int()
        _date = reader.tgread_date()
        _seq = reader.read_int()
        _unread_count = reader.read_int()
        return cls(pts=_pts, qts=_qts, date=_date, seq=_seq, unread_count=_unread_count)

