from django.core.management.base import BaseCommand, CommandError

from replay_execution.services import ReplayExecutionIntegrityService


class Command(BaseCommand):
    help = "Verify replay fixture execution, lineage, event chains and result consolidations."

    def handle(self, *args, **options):
        result = ReplayExecutionIntegrityService.verify_all()
        self.stdout.write(str(result))
        if result["invalid"]:
            raise CommandError(f"Replay execution integrity failed for {result['invalid']} item(s).")
        self.stdout.write(self.style.SUCCESS("Replay execution integrity verification passed."))
