from telethon.tl.mtproto_request import MTProtoRequest


class PeerDialogs(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.peerDialogs#3371c354 dialogs:Vector<Dialog> messages:Vector<Message> chats:Vector<Chat> users:Vector<User> state:updates.State = messages.PeerDialogs"""

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

    def __init__(self, dialogs, messages, chats, users, state):
        """
        :param dialogs: Telegram type: «Dialog». Must be a list.
        :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.
        :param state: Telegram type: «updates.State».
        """
        super().__init__()

        self.dialogs = dialogs
        self.messages = messages
        self.chats = chats
        self.users = users
        self.state = state

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

        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.messages))
        for messages_item in self.messages:
            messages_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.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)

        self.state.on_send(writer)

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are None)"""
        return PeerDialogs(None, None, None, None, None)

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

        reader.read_int()  # Vector's constructor ID
        self.messages = []  # Initialize an empty list
        messages_len = reader.read_int()
        for _ in range(messages_len):
            messages_item = reader.tgread_object()
            self.messages.append(messages_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)

        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)

        self.state = reader.tgread_object()

    def __repr__(self):
        return 'messages.peerDialogs#3371c354 dialogs:Vector<Dialog> messages:Vector<Message> chats:Vector<Chat> users:Vector<User> state:updates.State = messages.PeerDialogs'

    def __str__(self):
        return '(messages.peerDialogs (ID: 0x3371c354) = (dialogs={}, messages={}, chats={}, users={}, state={}))'.format(None if not self.dialogs else [str(_) for _ in self.dialogs], None if not self.messages else [str(_) for _ in self.messages], None if not self.chats else [str(_) for _ in self.chats], None if not self.users else [str(_) for _ in self.users], str(self.state))
