from django.core.management.base import BaseCommand, CommandError
from wagtail.models import Site

from ...services import generate_capacitor_project, get_settings_for_site


class Command(BaseCommand):
    help = "Initialize a generated mobile app shell for a site."

    def add_arguments(self, parser):
        parser.add_argument("--site-id", type=int, required=True)

    def handle(self, *args, **options):
        site = Site.objects.filter(pk=options["site_id"]).first()
        if site is None:
            raise CommandError("Site not found.")
        output_dir = generate_capacitor_project(
            site,
            get_settings_for_site(site),
            include_platform_dirs=False,
        )
        self.stdout.write(self.style.SUCCESS(str(output_dir)))
