My phone keeps shutting down and rebooting over and over!

A

AC Question

Help please!

I have a Samsung S6.
My phone keeps shutting down and rebooting multiple times. Sometimes while I am using it, sometimes when I haven't touched it in a while, or sometimes when I plug it in to charge.
I also need to know that if I do a factory reset will my phone still be unlocked?
My provider gave me 3 different unlock codes and none of them worked, I then had to go to a phone store to have them unlock it with a program. I am currently in a different country than where I originally purchased my phone so I am hesitant to factory reset it.

Any help would be great!