from ....tl.mtproto_request import MTProtoRequest


class CreateChatRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.createChat#09cb126e users:Vector<InputUser> title:string = Updates"""

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

    def __init__(self, users, title):
        """
        :param users: Telegram type: «InputUser». Must be a list.
        :param title: Telegram type: «string».

        :returns Updates: Instance of either UpdatesTooLong, UpdateShortMessage, UpdateShortChatMessage, UpdateShort, UpdatesCombined, UpdatesTg, UpdateShortSentMessage.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.users = users
        self.title = title

    def on_send(self, writer):
        writer.write_int(CreateChatRequest.constructor_id, signed=False)
        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.tgwrite_string(self.title)

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

    def on_response(self, reader):
        self.result = reader.tgread_object()

    def __repr__(self):
        return 'messages.createChat#09cb126e users:Vector<InputUser> title:string = Updates'

    def __str__(self):
        return '(messages.createChat (ID: 0x9cb126e) = (users={}, title={}))'.format(None if not self.users else [str(_) for _ in self.users], str(self.title))
