from django.contrib.auth import get_user_model

User = get_user_model()


def seed_superuser(*, email: str, password: str):
    """Create or update superuser so password matches (idempotent for local dev / compose restarts)."""
    existing = User.objects.filter(email__iexact=email).first()
    if existing:
        existing.is_superuser = True
        existing.is_staff = True
        existing.is_active = True
        existing.set_password(password)
        existing.save()
        return existing
    return User.objects.create_superuser(email=email, password=password)
