One way to boot the computer to macOS would be to connect a USB 3.0 external drive (HDD/SSD) to the iMac. Boot to internet recovery and install macOS on the external drive. (You may need to first run the Disk Utility to create a Mac OS Extended (Journaled)
or APFS
volume.) Once the iMac is up and running, you can open the System Information application and view the status of the internal SATA/SATA Express
hardware.
The most likely cause of your problem would be the failure of the internal drive. You could continue to use the iMac using the external drive or replace the internal drive. An example video of the replacement procedure can be found at this OWC website.
Often, it is possible to put a internal drive in a USB 3.0 shell which can be externally connected to the iMac. If the internal drive needs to be replaced, you then exchange the bad drive with the drive in the shell.
If you decide to use a external drive, you may want to consider a thunderbolt SSD drive. These types of drives will give you the maximum performance.