Mac starts up to a question mark factory reset
I tried to erase my disks from Disk Utility for a factory reset. However some of them were unable to be erased. When I restarted my computer the file with a question mark icon appeared. Following the official support website I opened the macOS Utilities from macOS Recovery and tried to first aid the disks. There were no problems with Disk Images: Apple disk image Media and OS X Base System. When I tried to repair the AppleAPFSMedia under Internal it said that First Aid found corruption and to run First Aid from Recovery, which is what I am already doing with command + R. For the disks under such as Macintosh HD, Macintosh HD - Data, and Update, all of them said that First Aid process has failed. If possible back up the data on this volume. All of the drives mentioned above were erased in the beginning when I was preparing for the factory reset. So all of them have been erased and has 1000 GB of storage available. I tried to reinstall macOS as well from recovery mode but it said that an error occurred while preparing the installation. Try running this application again. I tried it again but alas it doesn't work. Any help? I just want to successfully factory reset my Mac but now I can't even open it without the gray question mark screen.
iMac