# Path: dhis2_core/src/dhis2/code_list/models/svcm.py
# class CodeList(BaseEntity):
#     type: Literal["optionSets", "categories"] = "optionSets"
#     version: Union[str, int] = "1"
#     codes: List[Code] = []


import logging
from typing import List
from fhir.resources.bundle import Bundle, BundleEntry, BundleEntryRequest
from fhir.resources.codesystem import CodeSystem, CodeSystemConcept
from fhir.resources.identifier import Identifier
from fhir.resources.valueset import ValueSet, ValueSetCompose, ValueSetComposeInclude
from .models.svcm import CodeList

    return resource


def build_svcm_valueset(code_list: CodeList, base_url: str) -> ValueSet:
    resource = ValueSet()
    resource.url = f"{base_url}/api/{code_list.type}/{code_list.id}/valueSet"

    resource.identifier = [Identifier()]
    resource.identifier[0].system = f"{base_url}/api/{code_list.type}"
    resource.identifier[0].value = code_list.id

    if code_list.code:
        identifier = Identifier()
        identifier.system = f"{base_url}/api/{code_list.type}"
        identifier.value = code_list.code

        resource.identifier.append(identifier)

    resource.status = "active"
    resource.version = str(code_list.version)
    resource.name = code_list.name
    resource.title = code_list.name
    resource.description = code_list.name
    resource.experimental = False
    resource.immutable = True
    resource.compose = ValueSetCompose()
    resource.compose.include = [ValueSetComposeInclude()]
    resource.compose.include[0].system = f"{base_url}/api/{code_list.type}/{code_list.id}/codeSystem"


# Path: dhis2_core/src/dhis2/code_list/models/svcm.py
# class CodeList(BaseEntity):
#     type: Literal["optionSets", "categories"] = "optionSets"
#     version: Union[str, int] = "1"
#     codes: List[Code] = []


# Path: dhis2_core/src/dhis2/code_list/svcm_resources.py
import logging
from typing import List
from fhir.resources.bundle import Bundle, BundleEntry, BundleEntryRequest
from fhir.resources.codesystem import CodeSystem, CodeSystemConcept
from fhir.resources.identifier import Identifier
from fhir.resources.valueset import ValueSet, ValueSetCompose, ValueSetComposeInclude
from .models.svcm import CodeList


    return resource


def build_svcm_valueset(code_list: CodeList, base_url: str) -> ValueSet:
    resource = ValueSet()
    resource.url = f"{base_url}/api/{code_list.type}/{code_list.id}/valueSet"

    resource.identifier = [Identifier()]
    resource.identifier[0].system = f"{base_url}/api/{code_list.type}"
    resource.identifier[0].value = code_list.id

    if code_list.code:
        identifier = Identifier()
        identifier.system = f"{base_url}/api/{code_list.type}"
        identifier.value = code_list.code

        resource.identifier.append(identifier)

    resource.status = "active"
    resource.version = str(code_list.version)
    resource.name = code_list.name
    resource.title = code_list.name
    resource.description = code_list.name
    resource.experimental = False
    resource.immutable = True
    resource.compose = ValueSetCompose()
    resource.compose.include = [ValueSetComposeInclude()]
    resource.compose.include[0].system = f"{base_url}/api/{code_list.type}/{code_list.id}/codeSystem"


    return resource