A generator will keep the system running even if the battery is disconnected for a second
So it likely isn’t a battery issue nor a headlight circuit issue
Assuming the generator is working
So the problem is most likely where Bartamos suggested
Between key switch and coil
-a