from collections import OrderedDict
from collections.abc import Generator, Iterable
from typing import Any, TypeVar

from django.core.management.base import BaseCommand, CommandParser
from django.db import models, transaction
from django.db.models import QuerySet
from wagtail.search.backends.base import BaseSearchBackend, NullIndex

_T = TypeVar("_T")

DEFAULT_CHUNK_SIZE: int

def group_models_by_index(backend: BaseSearchBackend, models: list[type]) -> OrderedDict[NullIndex, list[type]]: ...

class Command(BaseCommand):
    verbosity: int
    def write(self, *args: Any, **kwargs: Any) -> None: ...
    def update_backend(self, backend_name: str, schema_only: bool = False, chunk_size: int = ...) -> None: ...
    def add_arguments(self, parser: CommandParser) -> None: ...
    def handle(self, **options: Any) -> None: ...
    def print_newline(self) -> None: ...
    def print_iter_progress(self, iterable: Iterable[_T]) -> Generator[_T]: ...
    @transaction.atomic
    def queryset_chunks(self, qs: QuerySet[models.Model], chunk_size: int = ...) -> Generator[list[models.Model]]: ...
