from ...tl.tlobject import TLObject


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

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

    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".

        Constructor for ChatParticipants: Instance of either ChatParticipantsForbidden, ChatParticipants.
        """
        super().__init__()

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

    def to_dict(self):
        return {
            'chat_id': self.chat_id,
            'participants': [] if self.participants is None else [None if x is None else x.to_dict() for x in self.participants],
            'version': self.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 _x in self.participants:
            _x.on_send(writer)

        writer.write_int(self.version)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=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
        _len = reader.read_int()
        for _ in range(_len):
            _x = reader.tgread_object()
            self.participants.append(_x)

        self.version = reader.read_int()

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

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

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