from telethon.tl.mtproto_request import MTProtoRequest


class ChatParticipants(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    chatParticipants#3f460fed chat_id:int participants:Vector<ChatParticipant> version:int = ChatParticipants"""

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

    def __init__(self, chat_id, participants, version):
        """
        :param chat_id: Telegram type: «int».
        :param participants: Telegram type: «ChatParticipant». Must be a list.
        :param version: Telegram type: «int».
        """
        super().__init__()

        self.chat_id = chat_id
        self.participants = participants
        self.version = version

    def on_send(self, writer):
        writer.write_int(ChatParticipants.constructor_id, signed=False)
        writer.write_int(self.chat_id)
        writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
        writer.write_int(len(self.participants))
        for participants_item in self.participants:
            participants_item.on_send(writer)

        writer.write_int(self.version)

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

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

        self.version = reader.read_int()

    def __repr__(self):
        return 'chatParticipants#3f460fed chat_id:int participants:Vector<ChatParticipant> version:int = ChatParticipants'

    def __str__(self):
        return '(chatParticipants (ID: 0x3f460fed) = (chat_id={}, participants={}, version={}))'.format(str(self.chat_id), None if not self.participants else [str(_) for _ in self.participants], str(self.version))
