from django.core.management.base import BaseCommand, CommandError  # noqa
from ...utils import export_wiki_content


class Command(BaseCommand):
    help = "Export wiki content for an app"

    def add_arguments(self, parser):
        parser.add_argument('app', nargs=1, type=str)
        parser.add_argument('--file', type=str)
        parser.add_argument('--prefix', type=str)
        parser.add_argument('--page-version', type=int)
        parser.add_argument('--image-version', type=int)

    def handle(self, *args, **options):
        app = options['app'][0]
        page_version = options['page_version']
        if page_version is None:
            page_version = 0
        image_version = options['image_version']
        if image_version is None:
            image_version = 0
        prefix = options['prefix']
        filename = options['file']
        if filename is None:
            filename = f"{app}.tinywiki.zip"

        export_wiki_content(app, filename, prefix, page_version, image_version)
