from django.core.management.base import BaseCommand
from clubs.models import ClubStadiumPurchase
from club_finance.bootstrap import prepare_club
from club_finance.repairs import repair_starter_stadium


class Command(BaseCommand):
    help='Repair starter stadium classification using additive journals and asset books; does not move wallet funds.'
    def handle(self,*args,**options):
        repaired=0
        for row in ClubStadiumPurchase.objects.select_related('club','stadium','ledger_entry').iterator():
            prepare_club(row.club)
            repaired+=repair_starter_stadium(row)
        self.stdout.write(f'Historical stadium corrections: {repaired}')
