from __future__ import annotations

from typing import TYPE_CHECKING, overload

from ..content import (
    DocAttribute,
    DocClass,
    DocFunction,
    DocModule,
    DocTypeAlias,
    Page,
    Section,
)
from .api_page import RenderAPIPage
from .docattribute import RenderDocAttribute
from .docclass import RenderDocClass
from .docfunction import RenderDocFunction
from .docmodule import RenderDocModule
from .doctypealias import RenderDocTypeAlias
from .reference_page import RenderReferencePage
from .reference_section import RenderReferenceSection

if TYPE_CHECKING:
    from ..typing import Documentable, RenderObjType


_class_mapping: dict[type[Documentable], type[RenderObjType]] = {
    DocAttribute: RenderDocAttribute,
    DocTypeAlias: RenderDocTypeAlias,
    DocClass: RenderDocClass,
    DocFunction: RenderDocFunction,
    DocModule: RenderDocModule,
    Page: RenderAPIPage,
    Section: RenderReferenceSection,
}


@overload
def get_render_type(obj: DocClass) -> type[RenderDocClass]: ...


@overload
def get_render_type(obj: DocFunction) -> type[RenderDocFunction]: ...


@overload
def get_render_type(obj: DocAttribute) -> type[RenderDocAttribute]: ...


@overload
def get_render_type(obj: DocTypeAlias) -> type[RenderDocTypeAlias]: ...


@overload
def get_render_type(obj: DocModule) -> type[RenderDocModule]: ...


@overload
def get_render_type(obj: Page) -> type[RenderAPIPage]: ...


@overload
def get_render_type(obj: Section) -> type[RenderReferenceSection]: ...


def get_render_type(obj: Documentable) -> type[RenderObjType]:
    if type(obj) in _class_mapping:
        return _class_mapping[type(obj)]
    else:
        msg = f"Cannot document object of type {type(obj)}"
        raise ValueError(msg)
