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


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 final: Telegram type: "true".
        :param pts: Telegram type: "int".
        :param timeout: Telegram type: "int".
        :param new_messages: Telegram type: "Message". Must be a list.
        :param other_updates: Telegram type: "Update". Must be a list.
        :param chats: Telegram type: "Chat". Must be a list.
        :param users: Telegram type: "User". Must be a list.

        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):
        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],
            'other_updates': [] if self.other_updates is None else [None if x is None else x.to_dict() for x in self.other_updates],
            'chats': [] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats],
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
        }

    def on_send(self, writer):
        writer.write_int(ChannelDifference.constructor_id, signed=False)
        flags = 0
        flags |= (1 << 0) if self.final else 0
        flags |= (1 << 1) if self.timeout else 0
        writer.write_int(flags)

        writer.write_int(self.pts)
        if self.timeout:
            writer.write_int(self.timeout)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.new_messages))
        for _x in self.new_messages:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.other_updates))
        for _x in self.other_updates:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.chats))
        for _x in self.chats:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.users))
        for _x in self.users:
            _x.on_send(writer)

    @staticmethod
    def empty():
        return ChannelDifference(None, None, None, None, None, None, None)

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 0)) != 0:
            self.final = True

        self.pts = reader.read_int()
        if (flags & (1 << 1)) != 0:
            self.timeout = reader.read_int()

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

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

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

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

    def __repr__(self):
        return 'updates.channelDifference#2064674e flags:# final:flags.0?true pts:int timeout:flags.1?int new_messages:Vector<Message> other_updates:Vector<Update> chats:Vector<Chat> users:Vector<User> = updates.ChannelDifference'

    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 final: Telegram type: "true".
        :param pts: Telegram type: "int".
        :param timeout: Telegram type: "int".

        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):
        return {
            'final': self.final,
            'pts': self.pts,
            'timeout': self.timeout,
        }

    def on_send(self, writer):
        writer.write_int(ChannelDifferenceEmpty.constructor_id, signed=False)
        flags = 0
        flags |= (1 << 0) if self.final else 0
        flags |= (1 << 1) if self.timeout else 0
        writer.write_int(flags)

        writer.write_int(self.pts)
        if self.timeout:
            writer.write_int(self.timeout)

    @staticmethod
    def empty():
        return ChannelDifferenceEmpty(None, None, None)

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 0)) != 0:
            self.final = True

        self.pts = reader.read_int()
        if (flags & (1 << 1)) != 0:
            self.timeout = reader.read_int()

    def __repr__(self):
        return 'updates.channelDifferenceEmpty#3e11affb flags:# final:flags.0?true pts:int timeout:flags.1?int = updates.ChannelDifference'

    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 final: Telegram type: "true".
        :param pts: Telegram type: "int".
        :param timeout: Telegram type: "int".
        :param top_message: Telegram type: "int".
        :param read_inbox_max_id: Telegram type: "int".
        :param read_outbox_max_id: Telegram type: "int".
        :param unread_count: Telegram type: "int".
        :param unread_mentions_count: Telegram type: "int".
        :param messages: Telegram type: "Message". Must be a list.
        :param chats: Telegram type: "Chat". Must be a list.
        :param users: Telegram type: "User". Must be a list.

        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):
        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],
            'chats': [] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats],
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
        }

    def on_send(self, writer):
        writer.write_int(ChannelDifferenceTooLong.constructor_id, signed=False)
        flags = 0
        flags |= (1 << 0) if self.final else 0
        flags |= (1 << 1) if self.timeout else 0
        writer.write_int(flags)

        writer.write_int(self.pts)
        if self.timeout:
            writer.write_int(self.timeout)

        writer.write_int(self.top_message)
        writer.write_int(self.read_inbox_max_id)
        writer.write_int(self.read_outbox_max_id)
        writer.write_int(self.unread_count)
        writer.write_int(self.unread_mentions_count)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.messages))
        for _x in self.messages:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.chats))
        for _x in self.chats:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.users))
        for _x in self.users:
            _x.on_send(writer)

    @staticmethod
    def empty():
        return ChannelDifferenceTooLong(None, None, None, None, None, None, None, None, None, None, None)

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 0)) != 0:
            self.final = True

        self.pts = reader.read_int()
        if (flags & (1 << 1)) != 0:
            self.timeout = reader.read_int()

        self.top_message = reader.read_int()
        self.read_inbox_max_id = reader.read_int()
        self.read_outbox_max_id = reader.read_int()
        self.unread_count = reader.read_int()
        self.unread_mentions_count = reader.read_int()
        reader.read_int()
        self.messages = []
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.messages.append(_x)

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

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

    def __repr__(self):
        return 'updates.channelDifferenceTooLong#6a9d7b35 flags:# final:flags.0?true pts:int timeout:flags.1?int top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int messages:Vector<Message> chats:Vector<Chat> users:Vector<User> = updates.ChannelDifference'

    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 new_messages: Telegram type: "Message". Must be a list.
        :param new_encrypted_messages: Telegram type: "EncryptedMessage". Must be a list.
        :param other_updates: Telegram type: "Update". Must be a list.
        :param chats: Telegram type: "Chat". Must be a list.
        :param users: Telegram type: "User". Must be a list.
        :param state: Telegram type: "updates.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):
        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],
            '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],
            'other_updates': [] if self.other_updates is None else [None if x is None else x.to_dict() for x in self.other_updates],
            'chats': [] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats],
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
            'state': None if self.state is None else self.state.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(Difference.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.new_messages))
        for _x in self.new_messages:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.new_encrypted_messages))
        for _x in self.new_encrypted_messages:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.other_updates))
        for _x in self.other_updates:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.chats))
        for _x in self.chats:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.users))
        for _x in self.users:
            _x.on_send(writer)

        self.state.on_send(writer)

    @staticmethod
    def empty():
        return Difference(None, None, None, None, None, None)

    def on_response(self, reader):
        reader.read_int()
        self.new_messages = []
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.new_messages.append(_x)

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

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

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

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

        self.state = reader.tgread_object()

    def __repr__(self):
        return 'updates.difference#00f49ca0 new_messages:Vector<Message> new_encrypted_messages:Vector<EncryptedMessage> other_updates:Vector<Update> chats:Vector<Chat> users:Vector<User> state:updates.State = updates.Difference'

    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 date: Telegram type: "date".
        :param seq: Telegram type: "int".

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

        self.date = date
        self.seq = seq

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

    def on_send(self, writer):
        writer.write_int(DifferenceEmpty.constructor_id, signed=False)
        writer.tgwrite_date(self.date)
        writer.write_int(self.seq)

    @staticmethod
    def empty():
        return DifferenceEmpty(None, None)

    def on_response(self, reader):
        self.date = reader.tgread_date()
        self.seq = reader.read_int()

    def __repr__(self):
        return 'updates.differenceEmpty#5d75a138 date:int seq:int = updates.Difference'

    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 new_messages: Telegram type: "Message". Must be a list.
        :param new_encrypted_messages: Telegram type: "EncryptedMessage". Must be a list.
        :param other_updates: Telegram type: "Update". Must be a list.
        :param chats: Telegram type: "Chat". Must be a list.
        :param users: Telegram type: "User". Must be a list.
        :param intermediate_state: Telegram type: "updates.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):
        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],
            '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],
            'other_updates': [] if self.other_updates is None else [None if x is None else x.to_dict() for x in self.other_updates],
            'chats': [] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats],
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
            'intermediate_state': None if self.intermediate_state is None else self.intermediate_state.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(DifferenceSlice.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.new_messages))
        for _x in self.new_messages:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.new_encrypted_messages))
        for _x in self.new_encrypted_messages:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.other_updates))
        for _x in self.other_updates:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.chats))
        for _x in self.chats:
            _x.on_send(writer)

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.users))
        for _x in self.users:
            _x.on_send(writer)

        self.intermediate_state.on_send(writer)

    @staticmethod
    def empty():
        return DifferenceSlice(None, None, None, None, None, None)

    def on_response(self, reader):
        reader.read_int()
        self.new_messages = []
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.new_messages.append(_x)

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

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

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

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

        self.intermediate_state = reader.tgread_object()

    def __repr__(self):
        return 'updates.differenceSlice#a8fb1981 new_messages:Vector<Message> new_encrypted_messages:Vector<EncryptedMessage> other_updates:Vector<Update> chats:Vector<Chat> users:Vector<User> intermediate_state:updates.State = updates.Difference'

    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 pts: Telegram type: "int".

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

        self.pts = pts

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

    def on_send(self, writer):
        writer.write_int(DifferenceTooLong.constructor_id, signed=False)
        writer.write_int(self.pts)

    @staticmethod
    def empty():
        return DifferenceTooLong(None)

    def on_response(self, reader):
        self.pts = reader.read_int()

    def __repr__(self):
        return 'updates.differenceTooLong#4afe8f6d pts:int = updates.Difference'

    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 pts: Telegram type: "int".
        :param qts: Telegram type: "int".
        :param date: Telegram type: "date".
        :param seq: Telegram type: "int".
        :param unread_count: Telegram type: "int".

        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):
        return {
            'pts': self.pts,
            'qts': self.qts,
            'date': self.date,
            'seq': self.seq,
            'unread_count': self.unread_count,
        }

    def on_send(self, writer):
        writer.write_int(State.constructor_id, signed=False)
        writer.write_int(self.pts)
        writer.write_int(self.qts)
        writer.tgwrite_date(self.date)
        writer.write_int(self.seq)
        writer.write_int(self.unread_count)

    @staticmethod
    def empty():
        return State(None, None, None, None, None)

    def on_response(self, reader):
        self.pts = reader.read_int()
        self.qts = reader.read_int()
        self.date = reader.tgread_date()
        self.seq = reader.read_int()
        self.unread_count = reader.read_int()

    def __repr__(self):
        return 'updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State'

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

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

