is it possible to condition the justification parameters of the last line of a paragraph according to the length of the paragraph? If yes, how?
Actually, there are three problems in one. Let me explain. Consider the following paragraphs:
1) The last line of the text is sometimes shorter than a certain fixed value, for example the value of \parindent. It would be preferable to either reduce the paragraph by one line or lengthen the last line.
2) Similarly, sometimes there is very little space left between the end of the last line and the margin. Here, it would be preferable to either reduce the length of the last line or extend the last line to the margin.
These two situations are framed in red on the diagram.
3) I consider both of these cases to be very unsightly. However, in the case of short paragraphs, changing the last line may change the entire paragraph and lead to an even more unsightly rendering. Also, I would like to know if we can give a minimum number of lines in the paragraph (for example 5 lines) to make the changes to cases 1 and 2.
Is it possible to create a code that can satisfy the three points above? (using the power of LuaLaTeX for example).
Currently, I use the command (\setlength\parfillskip {0pt \@plus 0.9\textwidth}) but it is not satisfactory. I thought about using prevgraf to solve problem 3), but I don't know how to do that.
Thanks for your help.

\parindent=0.5\textwidth(default), changing the indentation will have little if any effect on the last line of a paragraph. – John Kormylo Mar 15 '20 at 23:14\parfillskip=0ptand write long enough paragraphs. That is what Knuth recommends in the TeXbook. – Henri Menke Mar 16 '20 at 06:39