The spell casting functions are PROTECTED so you cannot call them at will from within your lua code.
Otherwise, you could easily program a bot that plays by itself.
https://wow.gamepedia.com/API_CastSpellByName
There must always be an active user action triggering a spellcast, which you could maybe do with a
SecureActionButtonTemplate. But as far as I understand, this will only allow you to cast one particular spell, so you would not be able to have some logic making the decision about which spell to cast.
Otherwise you could make a single button that always executes the ideal next spell of your rotation...