from django.core.management.base import BaseCommand
from submissions.utils import verify_and_validate_ocr_date_for_submission
from submissions.models import SubmissionFile


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument("--force", action="store_true", help="Force redo the OCR")

    def handle(self, *args, **options):
        for file in SubmissionFile.objects.prefetch_related(
            "response__puzzle",
            "response__submission__user",
        ):
            if not file.response.needs_manual_validation and not options.get(
                "force", False
            ):
                continue

            verify_and_validate_ocr_date_for_submission(file)
