Magnesium based primary (non rechargeable) and secondary (rechargeable) batteries