from django.core.management.base import BaseCommand
from play.models import QuizGame
from django.utils import timezone

class Command(BaseCommand):
    help = 'Bereinigt beendete Spiele'

    def handle(self, *args, **kwargs):
        expired_games = QuizGame.objects.filter(
            updated_at__lt=timezone.now() - timezone.timedelta(minutes=5))
        deleted_count = expired_games.count()
        expired_games.delete()
        self.stdout.write(f'{deleted_count} alte Spiele gelöscht.')
