# Path: dhis2_core/src/dhis2/code_list/models/icd10.py
# class ICD10Entity(BaseModel):
#     id: str = Field(alias="@id")
#     context: str = Field(alias="@context")
#     title: Optional[LanguageSpecificText]
#     definition: Optional[LanguageSpecificText]
#     longDefinition: Optional[LanguageSpecificText]
#     fullySpecifiedName: Optional[LanguageSpecificText]
#     source: Optional[str]
#     code: Optional[str]
#     note: Optional[List[LanguageSpecificText]]
#     codeRange: Optional[str]
# 
#     # chapter : if the entity is a chapter. (i.e. at the top level of the classification
#     # block : higher level entity which don't have codes
#     # category : An ICD entity that bears a code
# 
#     classKind: Optional[Literal["chapter", "block", "category", "modifiedcategory"]]
#     child: Union[List[str], List["ICD10Entity"]] = []
#     parent: Union[List[str], List["ICD10Entity"]] = []
#     browserUrl: Optional[str]


import logging
from typing import List
from dhis2.core.http import BaseHttpRequest
from dhis2.core.inventory import HostResolved
from .models.icd10 import ICD10Entity

def _icd10_fetch(
    host: HostResolved,
    release_id: str,
    language: str,
    id: str,
):
    req = BaseHttpRequest(host)
    url = f"icd/release/10/{release_id}"

    if id:
        url = f"icd/release/10/{release_id}/{id}"

    data = req.get(
        url,
        headers={
            "Accept-Language": language,
            "API-Version": "v2",
        },
    )

    return ICD10Entity(**data)


def _icd10_resolve_children(
    child: List[ICD10Entity],
    host: HostResolved,
    release_id: str,
    language: str,
) -> List[ICD10Entity]:

# Path: dhis2_core/src/dhis2/code_list/models/icd10.py
# class ICD10Entity(BaseModel):
#     id: str = Field(alias="@id")
#     context: str = Field(alias="@context")
#     title: Optional[LanguageSpecificText]
#     definition: Optional[LanguageSpecificText]
#     longDefinition: Optional[LanguageSpecificText]
#     fullySpecifiedName: Optional[LanguageSpecificText]
#     source: Optional[str]
#     code: Optional[str]
#     note: Optional[List[LanguageSpecificText]]
#     codeRange: Optional[str]
# 
#     # chapter : if the entity is a chapter. (i.e. at the top level of the classification
#     # block : higher level entity which don't have codes
#     # category : An ICD entity that bears a code
# 
#     classKind: Optional[Literal["chapter", "block", "category", "modifiedcategory"]]
#     child: Union[List[str], List["ICD10Entity"]] = []
#     parent: Union[List[str], List["ICD10Entity"]] = []
#     browserUrl: Optional[str]


# Path: dhis2_core/src/dhis2/code_list/icd10.py
import logging
from typing import List
from dhis2.core.http import BaseHttpRequest
from dhis2.core.inventory import HostResolved
from .models.icd10 import ICD10Entity


def _icd10_fetch(
    host: HostResolved,
    release_id: str,
    language: str,
    id: str,
):
    req = BaseHttpRequest(host)
    url = f"icd/release/10/{release_id}"

    if id:
        url = f"icd/release/10/{release_id}/{id}"

    data = req.get(
        url,
        headers={
            "Accept-Language": language,
            "API-Version": "v2",
        },
    )

    return ICD10Entity(**data)


def _icd10_resolve_children(
    child: List[ICD10Entity],
    host: HostResolved,
    release_id: str,
    language: str,
) -> List[ICD10Entity]:

    children: List[ICD10Entity] = []