from telethon.tl.mtproto_request import MTProtoRequest


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

    # Telegram's constructor ID (and unique identifier) for this class
    constructor_id = 0x74ae4240

    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».
        """
        super().__init__()

        self.updates = updates
        self.users = users
        self.chats = chats
        self.date = date
        self.seq = 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 updates_item in self.updates:
            updates_item.on_send(writer)

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

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

        writer.tgwrite_date(self.date)
        writer.write_int(self.seq)

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are 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
        updates_len = reader.read_int()
        for _ in range(updates_len):
            updates_item = reader.tgread_object()
            self.updates.append(updates_item)

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

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

        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:date seq:int = Updates'

    def __str__(self):
        return '(updates_tg (ID: 0x74ae4240) = (updates={}, users={}, chats={}, date={}, seq={}))'.format(None if not self.updates else [str(_) for _ in self.updates], None if not self.users else [str(_) for _ in self.users], None if not self.chats else [str(_) for _ in self.chats], str(self.date), str(self.seq))
