from ...tl.tlobject import TLObject


class UpdatesTg(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    updates_tg#74ae4240 updates:Vector<Update> users:Vector<User> chats:Vector<Chat> date:int seq:int = Updates"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0x74ae4240
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x8af52aac

    def __init__(self, updates, users, chats, date, seq):
        """
        :param updates: Telegram type: "Update". Must be a list.
        :param users: Telegram type: "User". Must be a list.
        :param chats: Telegram type: "Chat". Must be a list.
        :param date: Telegram type: "date".
        :param seq: Telegram type: "int".

        Constructor for Updates: Instance of either UpdatesTooLong, UpdateShortMessage, UpdateShortChatMessage, UpdateShort, UpdatesCombined, UpdatesTg, UpdateShortSentMessage.
        """
        super().__init__()

        self.updates = updates
        self.users = users
        self.chats = chats
        self.date = date
        self.seq = seq

    def to_dict(self):
        return {
            'updates': [] if self.updates is None else [None if x is None else x.to_dict() for x in self.updates],
            'users': [] if self.users is None else [None if x is None else x.to_dict() for x in self.users],
            'chats': [] if self.chats is None else [None if x is None else x.to_dict() for x in self.chats],
            'date': self.date,
            'seq': self.seq,
        }

    def on_send(self, writer):
        writer.write_int(UpdatesTg.constructor_id, signed=False)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.updates))
        for _x in self.updates:
            _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)

        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.tgwrite_date(self.date)
        writer.write_int(self.seq)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return UpdatesTg(None, None, None, None, None)

    def on_response(self, reader):
        reader.read_int()  # Vector's constructor ID
        self.updates = []  # Initialize an empty list
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.updates.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)

        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)

        self.date = reader.tgread_date()
        self.seq = reader.read_int()

    def __repr__(self):
        return 'updates_tg#74ae4240 updates:Vector<Update> users:Vector<User> chats:Vector<Chat> date:int seq:int = Updates'

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

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