In every situation, you will want to be in melee range in order to ensure you can make full use of your kit and utility. On top of that, you are classified in the game as a melee even if you do cast spells, meaning that you will get melee specific mechanics and not ranged ones. In conclusion, even if you are casting spells, you will want to do so from melee.