from ....tl.mtproto_request import MTProtoRequest


class ChannelParticipants(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    channels.channelParticipants#f56ee2a8 count:int participants:Vector<ChannelParticipant> users:Vector<User> = channels.ChannelParticipants"""

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

    def __init__(self, count, participants, users):
        """
        :param count: Telegram type: «int».
        :param participants: Telegram type: «ChannelParticipant». Must be a list.
        :param users: Telegram type: «User». Must be a list.

        Constructor for channels.ChannelParticipants: Instance of ChannelParticipants.
        """
        super().__init__()

        self.count = count
        self.participants = participants
        self.users = users

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

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

    def on_response(self, reader):
        self.count = 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)

        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)

    def __repr__(self):
        return 'channels.channelParticipants#f56ee2a8 count:int participants:Vector<ChannelParticipant> users:Vector<User> = channels.ChannelParticipants'

    def __str__(self):
        return '(channels.channelParticipants (ID: 0xf56ee2a8) = (count={}, participants={}, users={}))'.format(str(self.count), None if not self.participants else [str(_) for _ in self.participants], None if not self.users else [str(_) for _ in self.users])
