I did not mean replacing anything.
It will be done by connecting the phone to some software and just remove it all, but the operating system. No changes about hardware.
Computers are about the same. Format the hard drive and then there will be a new computer, all files will be gone + viruses and malware files.