from collections.abc import Generator, Iterable, Sized

from django.core.validators import MaxLengthValidator, MinLengthValidator
from django.db.models import Model
from django.utils.safestring import SafeString
from wagtail.rich_text.feature_registry import FeatureRegistry as FeatureRegistry
from wagtail.rich_text.rewriters import (
    EmbedRewriter as EmbedRewriter,
)
from wagtail.rich_text.rewriters import (
    LinkRewriter as LinkRewriter,
)
from wagtail.rich_text.rewriters import (
    MultiRuleRewriter as MultiRuleRewriter,
)

features: FeatureRegistry

def get_rewriter() -> MultiRuleRewriter: ...
def expand_db_html(html: str) -> str: ...
def extract_references_from_rich_text(html: str) -> Generator[tuple[type[Model], str, str, str]]: ...
def get_text_for_indexing(richtext: str) -> str: ...

class RichText:
    source: str
    def __init__(self, source: str | None) -> None: ...
    def __html__(self) -> str: ...
    def __str__(self) -> SafeString: ...
    def __bool__(self) -> bool: ...
    def __eq__(self, other: object) -> bool: ...

class EntityHandler:
    @staticmethod
    def get_model() -> type[Model]: ...
    @classmethod
    def get_instance(cls, attrs: dict[str, str]) -> Model: ...
    @classmethod
    def get_many(cls, attrs_list: list[dict[str, str]]) -> list[Model | None]: ...
    @staticmethod
    def expand_db_attributes(attrs: dict[str, str]) -> str: ...
    @classmethod
    def expand_db_attributes_many(cls, attrs_list: list[dict[str, str]]) -> list[str]: ...
    @classmethod
    def extract_references(cls, attrs: dict[str, str]) -> Iterable[tuple[type[Model], str, str, str]]: ...

class LinkHandler(EntityHandler): ...
class EmbedHandler(EntityHandler): ...

class RichTextMaxLengthValidator(MaxLengthValidator):
    def clean(self, x: Sized) -> int: ...

class RichTextMinLengthValidator(MinLengthValidator):
    def clean(self, x: Sized) -> int: ...
