IMO
a : Against bots I would say first the endgames then the opening then the middlegames.
On [for example] the Chessmaster program from 1100 to 1700 (apart from the fact that it is a program which normaly is not designed with an opening encyclopedia) we'll play vs bots with "a chess essential" (thanks to the lessons of notably Joshua Waitzkin) the bots present themselves as fake-weak players who play badly by giving us more or less very advantageous or winning positions then start playing well.
So what matters is rather to be good enough in tactics and to have good enough knowledge of the art of playing endgames to realize our decisive advantage.
+1800, the openings have an important role because some openings are just bad or ineffective against bots but also because if we play garbage or disadvantageous positions after the opening it will too often end in more or less painful defeats.
b : Against humans I would say first the middlegames then the openings then the endgames.
Humans play much more strategically with ideas and plans so it is important to have a background of strategic knowledge, to understand good enough positions and anticipate the attack plans of our opponents.
As Smyslov wrote, studying endings teaches you the characteristics of each piece, their power and potential. Their limits as well.
I’ve spent weeks standing at the edge of a board watching a young player chase a king all over the board with a queen or rook, check, check, check, … but never checkmate. For some people, this skill comes naturally. Most have to learn it.