You should take it to Apple or an authorized service center (whichever is available in your location).
Both my Macs got major hardware issues that had to be repaired – motherboard on m2 and charging port on m1. They didn't get fixed even with factory reset, although you can always try that on your machine or if you have a backup or Time Machine then you should just downgrade.
Topic:
App & System Services
SubTopic:
Hardware
Tags: