from django.core.management.base import BaseCommand

from api_v1.tasks import sync_external_printing_records


class Command(BaseCommand):
    help = '从外部 records 接口同步印染订单/任务'

    def add_arguments(self, parser):
        parser.add_argument('--limit', type=int, default=100)
        parser.add_argument(
            '--no-advance-cursor',
            action='store_true',
            help='只拉取并同步本批 records，不推进外部 cursor。适合本地/测试环境检查。',
        )

    def handle(self, *args, **options):
        payload = sync_external_printing_records.run(
            limit=options['limit'],
            advance_cursor=not options['no_advance_cursor'],
        )
        self.stdout.write(self.style.SUCCESS(str(payload)))
