Assuming something wrong in the motor, you could get new motor and swap out the core without needing to respoke motor into wheel.
https://www.greenbikekit.com/electric-bike-kit/rear-bldc/rm-g020-swx02-bafang-hub-motor-750w-500w.html
I have the same kit on two bikes. Though never had a motor...