To all those saying that enemies don't follow the same rules as players... Yes. In 5e, they generally do.
For example....
Archmage; quintessential high-end spellcaster enemy.
Archmage is a CR 12 creature, able to pose a moderate but not overwhelmiong threat to a group of 3-4 level 12 player characters.
In the Archmage block there is this section:
"Spellcasting. The archmage is an 18th-level spellcaster. Its spellcasting ability is Intelligence (spell save DC 17, +9 to hit with spell attacks). The archmage can cast disguise self and invisibility at will and has the following wizard spells prepared:
Cantrips (at will): fire bolt, light, mage hand, prestidigitation, shocking grasp
1st level (4 slots): detect magic, identify, mage armor*, magic missile
2nd level (3 slots): detect thoughts, mirror image, misty step
3rd level (3 slots): counterspell, fly, lightning bolt
4th level (3 slots): banishment, fire shield, stoneskin*
5th level (3 slots): cone of cold, scrying, wall of force
6th level (1 slot): globe of invulnerability
7th level (1 slot): teleport
8th level (1 slot): mind blank*
9th level (1 slot): time stop
*The archmage casts these spells on itself before combat."
This is exactly the spell capabilities an 18th level player character wizard would be expected to have, with the exception that the enemy spellcaster has a slightly lower save DC and attack bonus than the equivalent player Wizard would have, because the archmage is only rated at Pb+4, while an 18th level character is Pb+6.
They absolutely DO use the same rules and limitations as player characters, and do not generally cheat the rules with excessive extra casting capabilities. Resorting to cheating the stats is a sign of a poor GM, poor balance, or poor game design.