from django.core.management.base import BaseCommand, CommandError
from pathlib import Path
from core.utils import import_csv_bytes
class Command(BaseCommand):
    help="Import seed CSV (idempotent)"
    def add_arguments(self,parser):
        parser.add_argument("path", nargs="?", default="/data/imports/illustrations_seed.csv")
        parser.add_argument("--dry-run", action="store_true")
    def handle(self, path, dry_run, *args, **kwargs):
        p=Path(path)
        if not p.exists(): raise CommandError(f"CSV not found: {p}")
        report=import_csv_bytes(p.read_bytes(), dry_run=dry_run)
        self.stdout.write(self.style.SUCCESS(str(report)))
