You don't have to make something super customized - use the Dracolich template on an Ancient Dragon
There actually already exists options that do basically what you want. In the Monster Manual there is a monster template called Dracolich that you can apply to a stat block of any dragon adult or above (also in the Monster Manual) to create a dracolich.
Even as long-lived as they are, all dragons must eventually die. This thought doesn’t sit well with many dragons, some of which allow themselves to be transformed by necromantic energy and ancient rituals into powerful undead dracoliches.
Apply this template to any Ancient Dragon will get you a dragon with lich traits, spellcasting built in, and legendary and lair actions.
The only thing is doesn't quite do it match your expected CR. The CR of an Ancient Gold or Ancient Red Dracolich would be ~24 according to the template rules, which is just below the range you want.
If getting up to a CR 26+ is important to you, you still have options. Refer to DMG, Chapter 9, "Dungeon Master's Workshop", under the section "Creating a Monster", subsection "Modifying a Monster" (DMG p 273) and use that advice to add things to the monster to increase its CR to your desired level.
At the very least, using this template gets you 99% of the way to what you want without any from-scratch work needed and the DMG can get you the rest of the way there if needed.