from django.core.management.base import BaseCommand

from flower.app_version import set_cached_app_version_payload


class Command(BaseCommand):
    help = "更新 App 最新版本信息缓存"

    def add_arguments(self, parser):
        parser.add_argument("--major", type=int, required=True)
        parser.add_argument("--minor", type=int, required=True)
        parser.add_argument("--build", type=int, required=True)
        parser.add_argument("--download-url", required=True)

    def handle(self, *args, **options):
        payload = set_cached_app_version_payload(
            major=options["major"],
            minor=options["minor"],
            build=options["build"],
            download_url=options["download_url"],
        )
        self.stdout.write(self.style.SUCCESS(str(payload)))
