Magnesium-based dual-ion battery