I guess that’s the whole point of the thread. I assumed at least 16th. But it could be higher.
With proper planning they could scry and teleport or have different ways of countering the dragon’s defences. Once you hit 17th level, you are hitting 9th level spells. Lots of ways for magic to get into and out of places discreetly
Yeah, I guess if I were a thousand plus year dragon I'd have hired or forced a caster to do inner sanctum or similar for me. Even if the PCs scry, but that only gives you a view of the dragon from 10 feet away. I don't see how that makes much of a difference. Teleport? You've never seen the lair and only have a description of it. Good luck.
There are a few things you could do, but if you allow the invulnerability spell (I don't) that would mean you just have to take the caster out of the picture when the dragon notices they aren't taking damage. Burial at sea perhaps?
A lot just depends on the players. A 9th level spell can be awesome or the dragon can just choose to save. But looking at standard 9th level wizard spells as an example? I can't see anything that would make a huge difference in the fight.