from ....tl.tlobject import TLObject


class Difference(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    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"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0xf49ca0
    # Also the ID of its resulting type for fast checks
    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():
        """Returns an "empty" instance (attributes=None)"""
        return Difference(None, None, None, None, None, None)

    def on_response(self, reader):
        reader.read_int()  # Vector's constructor ID
        self.new_messages = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.new_messages.append(_x)

        reader.read_int()  # Vector's constructor ID
        self.new_encrypted_messages = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.new_encrypted_messages.append(_x)

        reader.read_int()  # Vector's constructor ID
        self.other_updates = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.other_updates.append(_x)

        reader.read_int()  # Vector's constructor ID
        self.chats = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.chats.append(_x)

        reader.read_int()  # Vector's constructor ID
        self.users = []  # Initialize an empty list
        _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)
