from ....tl.mtproto_request import MTProtoRequest


class SaveDraftRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.saveDraft#bc39e14b flags:# no_webpage:flags.1?true reply_to_msg_id:flags.0?int peer:InputPeer message:string entities:flags.3?Vector<MessageEntity> = Bool"""

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

    def __init__(self, peer, message, no_webpage=None, reply_to_msg_id=None, entities=None):
        """
        :param no_webpage: Telegram type: «true».
        :param reply_to_msg_id: Telegram type: «int».
        :param peer: Telegram type: «InputPeer».
        :param message: Telegram type: «string».
        :param entities: Telegram type: «MessageEntity». Must be a list.

        :returns Bool: This type has no constructors.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.no_webpage = no_webpage
        self.reply_to_msg_id = reply_to_msg_id
        self.peer = peer
        self.message = message
        self.entities = entities

    def on_send(self, writer):
        writer.write_int(SaveDraftRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 1) if self.no_webpage else 0
        flags |= (1 << 0) if self.reply_to_msg_id else 0
        flags |= (1 << 3) if self.entities else 0
        writer.write_int(flags)

        if self.reply_to_msg_id:
            writer.write_int(self.reply_to_msg_id)

        self.peer.on_send(writer)
        writer.tgwrite_string(self.message)
        if self.entities:
            writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
            writer.write_int(len(self.entities))
            for entities_item in self.entities:
                if entities_item:
                    entities_item.on_send(writer)

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

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

    def __repr__(self):
        return 'messages.saveDraft#bc39e14b flags:# no_webpage:flags.1?true reply_to_msg_id:flags.0?int peer:InputPeer message:string entities:flags.3?Vector<MessageEntity> = Bool'

    def __str__(self):
        return '(messages.saveDraft (ID: 0xbc39e14b) = (no_webpage={}, reply_to_msg_id={}, peer={}, message={}, entities={}))'.format(str(self.no_webpage), str(self.reply_to_msg_id), str(self.peer), str(self.message), None if not self.entities else [str(_) for _ in self.entities])
