"""File generated by TLObjects' generator. All changes will be ERASED"""
from ...tl.tlobject import TLObject
import os
import struct


class ChannelDifference(TLObject):
    CONSTRUCTOR_ID = 0x2064674e
    SUBCLASS_OF_ID = 0x29896f5d

    def __init__(self, pts, new_messages, other_updates, chats, users, final=None, timeout=None):
        """
        :param bool | None final:
        :param int pts:
        :param int | None timeout:
        :param list[TLObject] new_messages:
        :param list[TLObject] other_updates:
        :param list[TLObject] chats:
        :param list[TLObject] users:

        Constructor for updates.ChannelDifference: Instance of either ChannelDifferenceEmpty, ChannelDifferenceTooLong, ChannelDifference.
        """
        super().__init__()

        self.final = final
        self.pts = pts
        self.timeout = timeout
        self.new_messages = new_messages
        self.other_updates = other_updates
        self.chats = chats
        self.users = users

    def to_dict(self, recursive=True):
        return {
            'final': self.final,
            'pts': self.pts,
            'timeout': self.timeout,
            'new_messages': ([] if self.new_messages is None else [None if x is None else x.to_dict() for x in self.new_messages]) if recursive else self.new_messages,
            'other_updates': ([] if self.other_updates is None else [None if x is None else x.to_dict() for x in self.other_updates]) if recursive else self.other_updates,
            'chats': ([] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats]) if recursive else self.chats,
            'users': ([] if self.users is None else [None if x is None else x.to_dict() for x in self.users]) if recursive else self.users,
        }

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

    @staticmethod
    def from_reader(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 ChannelDifference(pts=_pts, new_messages=_new_messages, other_updates=_other_updates, chats=_chats, users=_users, final=_final, timeout=_timeout)

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

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


class ChannelDifferenceEmpty(TLObject):
    CONSTRUCTOR_ID = 0x3e11affb
    SUBCLASS_OF_ID = 0x29896f5d

    def __init__(self, pts, final=None, timeout=None):
        """
        :param bool | None final:
        :param int pts:
        :param int | None timeout:

        Constructor for updates.ChannelDifference: Instance of either ChannelDifferenceEmpty, ChannelDifferenceTooLong, ChannelDifference.
        """
        super().__init__()

        self.final = final
        self.pts = pts
        self.timeout = timeout

    def to_dict(self, recursive=True):
        return {
            'final': self.final,
            'pts': self.pts,
            'timeout': self.timeout,
        }

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

    @staticmethod
    def from_reader(reader):
        flags = reader.read_int()

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

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

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


class ChannelDifferenceTooLong(TLObject):
    CONSTRUCTOR_ID = 0x6a9d7b35
    SUBCLASS_OF_ID = 0x29896f5d

    def __init__(self, pts, top_message, read_inbox_max_id, read_outbox_max_id, unread_count, unread_mentions_count, messages, chats, users, final=None, timeout=None):
        """
        :param bool | None final:
        :param int pts:
        :param int | None timeout:
        :param int top_message:
        :param int read_inbox_max_id:
        :param int read_outbox_max_id:
        :param int unread_count:
        :param int unread_mentions_count:
        :param list[TLObject] messages:
        :param list[TLObject] chats:
        :param list[TLObject] users:

        Constructor for updates.ChannelDifference: Instance of either ChannelDifferenceEmpty, ChannelDifferenceTooLong, ChannelDifference.
        """
        super().__init__()

        self.final = final
        self.pts = pts
        self.timeout = timeout
        self.top_message = top_message
        self.read_inbox_max_id = read_inbox_max_id
        self.read_outbox_max_id = read_outbox_max_id
        self.unread_count = unread_count
        self.unread_mentions_count = unread_mentions_count
        self.messages = messages
        self.chats = chats
        self.users = users

    def to_dict(self, recursive=True):
        return {
            'final': self.final,
            'pts': self.pts,
            'timeout': self.timeout,
            'top_message': self.top_message,
            'read_inbox_max_id': self.read_inbox_max_id,
            'read_outbox_max_id': self.read_outbox_max_id,
            'unread_count': self.unread_count,
            'unread_mentions_count': self.unread_mentions_count,
            'messages': ([] if self.messages is None else [None if x is None else x.to_dict() for x in self.messages]) if recursive else self.messages,
            'chats': ([] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats]) if recursive else self.chats,
            'users': ([] if self.users is None else [None if x is None else x.to_dict() for x in self.users]) if recursive else self.users,
        }

    def __bytes__(self):
        return b''.join((
            b'5{\x9dj',
            struct.pack('<I', (1 if self.final else 0) | (2 if self.timeout else 0)),
            struct.pack('<i', self.pts),
            b'' if not self.timeout else (struct.pack('<i', self.timeout)),
            struct.pack('<i', self.top_message),
            struct.pack('<i', self.read_inbox_max_id),
            struct.pack('<i', self.read_outbox_max_id),
            struct.pack('<i', self.unread_count),
            struct.pack('<i', self.unread_mentions_count),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.messages)),b''.join(bytes(x) for x in self.messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.chats)),b''.join(bytes(x) for x in self.chats),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.users)),b''.join(bytes(x) for x in self.users),
        ))

    @staticmethod
    def from_reader(reader):
        flags = reader.read_int()

        _final = bool(flags & 1)
        _pts = reader.read_int()
        if flags & 2:
            _timeout = reader.read_int()
        else:
            _timeout = None
        _top_message = reader.read_int()
        _read_inbox_max_id = reader.read_int()
        _read_outbox_max_id = reader.read_int()
        _unread_count = reader.read_int()
        _unread_mentions_count = reader.read_int()
        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 ChannelDifferenceTooLong(pts=_pts, top_message=_top_message, read_inbox_max_id=_read_inbox_max_id, read_outbox_max_id=_read_outbox_max_id, unread_count=_unread_count, unread_mentions_count=_unread_mentions_count, messages=_messages, chats=_chats, users=_users, final=_final, timeout=_timeout)

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

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


class Difference(TLObject):
    CONSTRUCTOR_ID = 0xf49ca0
    SUBCLASS_OF_ID = 0x20482874

    def __init__(self, new_messages, new_encrypted_messages, other_updates, chats, users, state):
        """
        :param list[TLObject] new_messages:
        :param list[TLObject] new_encrypted_messages:
        :param list[TLObject] other_updates:
        :param list[TLObject] chats:
        :param list[TLObject] users:
        :param TLObject state:

        Constructor for updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
        """
        super().__init__()

        self.new_messages = new_messages
        self.new_encrypted_messages = new_encrypted_messages
        self.other_updates = other_updates
        self.chats = chats
        self.users = users
        self.state = state

    def to_dict(self, recursive=True):
        return {
            'new_messages': ([] if self.new_messages is None else [None if x is None else x.to_dict() for x in self.new_messages]) if recursive else self.new_messages,
            'new_encrypted_messages': ([] if self.new_encrypted_messages is None else [None if x is None else x.to_dict() for x in self.new_encrypted_messages]) if recursive else self.new_encrypted_messages,
            'other_updates': ([] if self.other_updates is None else [None if x is None else x.to_dict() for x in self.other_updates]) if recursive else self.other_updates,
            'chats': ([] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats]) if recursive else self.chats,
            'users': ([] if self.users is None else [None if x is None else x.to_dict() for x in self.users]) if recursive else self.users,
            'state': (None if self.state is None else self.state.to_dict()) if recursive else self.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(bytes(x) for x in self.new_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.new_encrypted_messages)),b''.join(bytes(x) for x in self.new_encrypted_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.other_updates)),b''.join(bytes(x) for x in self.other_updates),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.chats)),b''.join(bytes(x) for x in self.chats),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.users)),b''.join(bytes(x) for x in self.users),
            bytes(self.state),
        ))

    @staticmethod
    def from_reader(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 Difference(new_messages=_new_messages, new_encrypted_messages=_new_encrypted_messages, other_updates=_other_updates, chats=_chats, users=_users, state=_state)

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

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


class DifferenceEmpty(TLObject):
    CONSTRUCTOR_ID = 0x5d75a138
    SUBCLASS_OF_ID = 0x20482874

    def __init__(self, date, seq):
        """
        :param datetime.datetime | None date:
        :param int seq:

        Constructor for updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
        """
        super().__init__()

        self.date = date
        self.seq = seq

    def to_dict(self, recursive=True):
        return {
            'date': self.date,
            'seq': self.seq,
        }

    def __bytes__(self):
        return b''.join((
            b'8\xa1u]',
            b'\0\0\0\0' if self.date is None else struct.pack('<I', int(self.date.timestamp())),
            struct.pack('<i', self.seq),
        ))

    @staticmethod
    def from_reader(reader):
        _date = reader.tgread_date()
        _seq = reader.read_int()
        return DifferenceEmpty(date=_date, seq=_seq)

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

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


class DifferenceSlice(TLObject):
    CONSTRUCTOR_ID = 0xa8fb1981
    SUBCLASS_OF_ID = 0x20482874

    def __init__(self, new_messages, new_encrypted_messages, other_updates, chats, users, intermediate_state):
        """
        :param list[TLObject] new_messages:
        :param list[TLObject] new_encrypted_messages:
        :param list[TLObject] other_updates:
        :param list[TLObject] chats:
        :param list[TLObject] users:
        :param TLObject intermediate_state:

        Constructor for updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
        """
        super().__init__()

        self.new_messages = new_messages
        self.new_encrypted_messages = new_encrypted_messages
        self.other_updates = other_updates
        self.chats = chats
        self.users = users
        self.intermediate_state = intermediate_state

    def to_dict(self, recursive=True):
        return {
            'new_messages': ([] if self.new_messages is None else [None if x is None else x.to_dict() for x in self.new_messages]) if recursive else self.new_messages,
            'new_encrypted_messages': ([] if self.new_encrypted_messages is None else [None if x is None else x.to_dict() for x in self.new_encrypted_messages]) if recursive else self.new_encrypted_messages,
            'other_updates': ([] if self.other_updates is None else [None if x is None else x.to_dict() for x in self.other_updates]) if recursive else self.other_updates,
            'chats': ([] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats]) if recursive else self.chats,
            'users': ([] if self.users is None else [None if x is None else x.to_dict() for x in self.users]) if recursive else self.users,
            'intermediate_state': (None if self.intermediate_state is None else self.intermediate_state.to_dict()) if recursive else self.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(bytes(x) for x in self.new_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.new_encrypted_messages)),b''.join(bytes(x) for x in self.new_encrypted_messages),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.other_updates)),b''.join(bytes(x) for x in self.other_updates),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.chats)),b''.join(bytes(x) for x in self.chats),
            b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.users)),b''.join(bytes(x) for x in self.users),
            bytes(self.intermediate_state),
        ))

    @staticmethod
    def from_reader(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 DifferenceSlice(new_messages=_new_messages, new_encrypted_messages=_new_encrypted_messages, other_updates=_other_updates, chats=_chats, users=_users, intermediate_state=_intermediate_state)

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

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


class DifferenceTooLong(TLObject):
    CONSTRUCTOR_ID = 0x4afe8f6d
    SUBCLASS_OF_ID = 0x20482874

    def __init__(self, pts):
        """
        :param int pts:

        Constructor for updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
        """
        super().__init__()

        self.pts = pts

    def to_dict(self, recursive=True):
        return {
            'pts': self.pts,
        }

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

    @staticmethod
    def from_reader(reader):
        _pts = reader.read_int()
        return DifferenceTooLong(pts=_pts)

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

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


class State(TLObject):
    CONSTRUCTOR_ID = 0xa56c2a3e
    SUBCLASS_OF_ID = 0x23df1a01

    def __init__(self, pts, qts, date, seq, unread_count):
        """
        :param int pts:
        :param int qts:
        :param datetime.datetime | None date:
        :param int seq:
        :param int unread_count:

        Constructor for updates.State: Instance of State.
        """
        super().__init__()

        self.pts = pts
        self.qts = qts
        self.date = date
        self.seq = seq
        self.unread_count = unread_count

    def to_dict(self, recursive=True):
        return {
            'pts': self.pts,
            'qts': self.qts,
            'date': self.date,
            'seq': self.seq,
            'unread_count': self.unread_count,
        }

    def __bytes__(self):
        return b''.join((
            b'>*l\xa5',
            struct.pack('<i', self.pts),
            struct.pack('<i', self.qts),
            b'\0\0\0\0' if self.date is None else struct.pack('<I', int(self.date.timestamp())),
            struct.pack('<i', self.seq),
            struct.pack('<i', self.unread_count),
        ))

    @staticmethod
    def from_reader(reader):
        _pts = reader.read_int()
        _qts = reader.read_int()
        _date = reader.tgread_date()
        _seq = reader.read_int()
        _unread_count = reader.read_int()
        return State(pts=_pts, qts=_qts, date=_date, seq=_seq, unread_count=_unread_count)

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

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