# Path: dhis2_core/src/dhis2/code_list/icd11.py
# def fetch_icd11_dhis2_option_sets(
#     host: HostResolved,
#     linearizationname: str,
#     release_id: str,
#     language: str,
#     root_id: str,
# ):
#     log.info("ICD11 export job started")
# 
#     icd11 = _icd11_fetch_all(host, linearizationname, release_id, language, root_id)
# 
#     log.info("Converting to DHIS2 optionset/options payload")
#     dhis2 = _dhis2_make_option_sets(icd11)
# 
#     log.info("ICD11 export job finished")
# 
#     return dhis2
# 
# Path: dhis2_core/src/dhis2/code_list/icd10.py
# def fetch_icd10_dhis2_option_sets(
#     host: HostResolved,
#     release_id: str,
#     language: str,
#     root_id: str,
# ):
#     log.info("ICD10 export job started")
# 
#     icd10 = _icd10_fetch_all(host, release_id, language, root_id)
# 
#     log.info("Converting to DHIS2 optionset/options payload")
#     dhis2 = _dhis2_make_option_sets(icd10)
# 
#     log.info("ICD10 export job finished")
# 
#     return dhis2


import json
import logging
import sys
import click
from dhis2.core.inventory import resolve_one
from dhis2.core.utils import parse_file
from . import svcm
from .icd11 import fetch_icd11_dhis2_option_sets
from .icd10 import fetch_icd10_dhis2_option_sets


@click.group("code-list")
def cli_code_list():
    """ Various commands for code-list data exchange """
    pass


@cli_code_list.command("icd11")
@click.argument("host-id")
@click.option("--linearizationname", default="mms")
@click.option("--release-id", default="2020-09")
@click.option("--language", default="en")
@click.option("--root-id")
@click.pass_obj
def cmd_code_list_icd11(
    ctx,
    host_id: str,
    linearizationname: str,
    release_id: str,
    language: str,
    root_id: str,
):
    """ Generate dhis2 option sets from icd11 source **experimental** """
    host = resolve_one(host_id, ctx.inventory)

    if not "icd11" == host.type:
        log.error(f"Invalid source type '{host.type}', only 'icd11' sources are allowed")
        sys.exit(-1)


# Path: dhis2_core/src/dhis2/code_list/icd11.py
# def fetch_icd11_dhis2_option_sets(
#     host: HostResolved,
#     linearizationname: str,
#     release_id: str,
#     language: str,
#     root_id: str,
# ):
#     log.info("ICD11 export job started")
# 
#     icd11 = _icd11_fetch_all(host, linearizationname, release_id, language, root_id)
# 
#     log.info("Converting to DHIS2 optionset/options payload")
#     dhis2 = _dhis2_make_option_sets(icd11)
# 
#     log.info("ICD11 export job finished")
# 
#     return dhis2
# 
# Path: dhis2_core/src/dhis2/code_list/icd10.py
# def fetch_icd10_dhis2_option_sets(
#     host: HostResolved,
#     release_id: str,
#     language: str,
#     root_id: str,
# ):
#     log.info("ICD10 export job started")
# 
#     icd10 = _icd10_fetch_all(host, release_id, language, root_id)
# 
#     log.info("Converting to DHIS2 optionset/options payload")
#     dhis2 = _dhis2_make_option_sets(icd10)
# 
#     log.info("ICD10 export job finished")
# 
#     return dhis2


# Path: dhis2_core/src/dhis2/code_list/cli.py
import json
import logging
import sys
import click
from dhis2.core.inventory import resolve_one
from dhis2.core.utils import parse_file
from . import svcm
from .icd11 import fetch_icd11_dhis2_option_sets
from .icd10 import fetch_icd10_dhis2_option_sets



@click.group("code-list")
def cli_code_list():
    """ Various commands for code-list data exchange """
    pass


@cli_code_list.command("icd11")
@click.argument("host-id")
@click.option("--linearizationname", default="mms")
@click.option("--release-id", default="2020-09")
@click.option("--language", default="en")
@click.option("--root-id")
@click.pass_obj
def cmd_code_list_icd11(
    ctx,
    host_id: str,
    linearizationname: str,
    release_id: str,
    language: str,
    root_id: str,
):
    """ Generate dhis2 option sets from icd11 source **experimental** """
    host = resolve_one(host_id, ctx.inventory)

    if not "icd11" == host.type:
        log.error(f"Invalid source type '{host.type}', only 'icd11' sources are allowed")
        sys.exit(-1)


    option_sets = fetch_icd11_dhis2_option_sets(