from collections import Counter, OrderedDict
from typing import Any, Dict, Iterable, List, Optional, Pattern, Sequence, Tuple, Type, Union

from django.db.models.base import Model
from django.http.request import HttpRequest
from rest_framework.compat import coreapi

def common_path(paths: Iterable[str]) -> str: ...
def get_pk_name(model: Type[Model]) -> str: ...
def is_api_view(callback: Any) -> bool: ...

INSERT_INTO_COLLISION_FMT: str = ...

class LinkNode(OrderedDict):
    links: List[Any]
    methods_counter: Counter
    def get_available_key(self, preferred_key: str) -> str: ...

def insert_into(target: LinkNode, keys: Sequence[str], value: Any) -> None: ...
def distribute_links(obj: LinkNode) -> None: ...
def is_custom_action(action: str) -> bool: ...

_APIEndpoint = Tuple[str, str, Any]

def endpoint_ordering(endpoint: _APIEndpoint) -> Tuple[str, int]: ...

_PATH_PARAMETER_COMPONENT_RE: Pattern = ...

class EndpointEnumerator(object):
    patterns: List[Any]
    def __init__(self, patterns: Optional[List[Any]] = ..., urlconf: Optional[str] = ...) -> None: ...
    def get_api_endpoints(self, patterns: Optional[List[Any]] = ..., prefix: str = ...) -> List[_APIEndpoint]: ...
    def get_path_from_regex(self, path_regex: Union[Pattern, str]) -> str: ...
    def should_include_endpoint(self, path: str, callback: Any) -> bool: ...
    def get_allowed_methods(self, callback: Any) -> List[str]: ...

class SchemaGenerator(object):
    urlconf: Optional[str]
    title: Optional[str]
    description: Optional[str]
    patterns: List[Any]
    url: Optional[str]
    endpoints: Optional[Sequence[_APIEndpoint]]

    default_mapping: Dict[str, str] = ...
    endpoint_inspector_cls: Type[EndpointEnumerator] = ...
    coerce_method_names: Optional[Dict[str, str]] = ...

    coerce_path_pk: Optional[bool] = ...
    def __init__(
        self,
        title: Optional[str] = ...,
        url: Optional[str] = ...,
        description: Optional[str] = ...,
        patterns: Optional[List[Any]] = ...,
        urlconf: Optional[str] = ...,
    ) -> None: ...
    def get_schema(self, request: Optional[HttpRequest] = ..., public: bool = ...) -> Optional[coreapi.Document]: ...
    def get_links(self, request: Optional[HttpRequest] = ...) -> Optional[LinkNode]: ...
    def determine_path_prefix(self, paths: Sequence[str]) -> str: ...
    def create_view(self, callback: Any, method: str, request: Optional[HttpRequest] = ...) -> Any: ...
    def has_view_permissions(self, path: str, method: str, view) -> bool: ...
    def coerce_path(self, path: str, method: str, view) -> str: ...
    def get_keys(self, subpath: str, method: str, view) -> List[str]: ...
