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

from matches.interactive import InteractiveMatchRunnerService


class Command(BaseCommand):
    help = "Configure a not-yet-started match for the interactive v2.2 runner."

    def add_arguments(self, parser):
        parser.add_argument("--match-id", required=True)
        parser.add_argument("--segment-seconds", type=int, default=60)

    def handle(self, *args, **options):
        try:
            session = InteractiveMatchRunnerService.prepare(
                match_id=options["match_id"],
                segment_duration_seconds=options["segment_seconds"],
            )
        except Exception as exc:
            raise CommandError(str(exc)) from exc
        self.stdout.write(self.style.SUCCESS(
            f"Interactive session {session.pk} PREPARED for match {session.match_id}."
        ))
