from collections import OrderedDict
from typing import Any

from rest_framework import relations, serializers
from rest_framework.fields import Field

from .utils import get_object_detail_url as get_object_detail_url

class TypeField(Field):
    def get_attribute(self, instance: Any) -> Any: ...
    def to_representation(self, obj: Any) -> str: ...

class DetailUrlField(Field):
    def get_attribute(self, instance: Any) -> Any: ...
    def to_representation(self, url: str) -> str: ...

class PageHtmlUrlField(Field):
    def get_attribute(self, instance: Any) -> Any: ...
    def to_representation(self, page: Any) -> str | None: ...

class PageTypeField(Field):
    def get_attribute(self, instance: Any) -> Any: ...
    def to_representation(self, page: Any) -> str | None: ...

class PageLocaleField(Field):
    def get_attribute(self, instance: Any) -> Any: ...
    def to_representation(self, page: Any) -> str: ...

class RelatedField(relations.RelatedField):
    serializer_class: type[BaseSerializer]
    def __init__(self, *args: Any, **kwargs: Any) -> None: ...
    def to_representation(self, value: Any) -> dict[str, Any]: ...

class PageParentField(relations.RelatedField):
    def get_attribute(self, instance: Any) -> Any: ...
    def to_representation(self, value: Any) -> dict[str, Any]: ...

class PageAliasOfField(relations.RelatedField):
    def get_attribute(self, instance: Any) -> Any: ...
    def to_representation(self, value: Any) -> dict[str, Any]: ...

class ChildRelationField(Field):
    serializer_class: type[BaseSerializer]
    def __init__(self, *args: Any, **kwargs: Any) -> None: ...
    def to_representation(self, value: Any) -> list[dict[str, Any]]: ...

class StreamField(Field):
    def to_representation(self, value: Any) -> Any: ...

class TagsField(Field):
    def to_representation(self, value: Any) -> list[str]: ...

class BaseSerializer(serializers.ModelSerializer):
    serializer_field_mapping: dict[type, type[Field]]
    serializer_related_field = RelatedField
    type: TypeField
    detail_url: DetailUrlField
    def to_representation(self, instance: Any) -> OrderedDict[str, Any]: ...
    def build_property_field(self, field_name: str, model_class: type) -> tuple[type[Field], dict[str, Any]]: ...
    def build_relational_field(self, field_name: str, relation_info: Any) -> tuple[type[Field], dict[str, Any]]: ...

class PageSerializer(BaseSerializer):
    type: PageTypeField  # type: ignore[assignment]
    locale: PageLocaleField
    html_url: PageHtmlUrlField
    parent: PageParentField
    alias_of: PageAliasOfField
    def build_relational_field(self, field_name: str, relation_info: Any) -> tuple[type[Field], dict[str, Any]]: ...

def get_serializer_class(
    model: type,
    field_names: list[str],
    meta_fields: list[str],
    field_serializer_overrides: dict[str, Any] | None = None,
    child_serializer_classes: dict[str, Any] | None = None,
    base: type[BaseSerializer] = ...,
) -> type[BaseSerializer]: ...
