from typing import Optional
from typing import Dict
from typing import Any
import warnings


def get_settings(
    conf_group: Optional[Dict[str, Any]], name_map: Optional[Dict[str, str]] = None
) -> Dict[Any, Any]:
    """
    Lookup configuration values config, environment or KeyVault.

    Parameters
    ----------
    conf_group : Optional[Dict[str, Any]]
        The configuration dictionary
    name_map : Optional[Dict[str, str]], optional
        Optional mapping to re-write setting names,
        by default None

    Returns
    -------
    Dict[Any, Any]
        Dictionary of resolved settings

    Raises
    ------
    NotImplementedError
        Keyvault storage is not yet implemented

    """
    if not conf_group:
        return {}
    setting_dict: Dict[str, Any] = conf_group.copy()

    for arg_name, arg_value in conf_group.items():
        target_name = arg_name
        if name_map:
            target_name = name_map.get(target_name, target_name)

        if isinstance(arg_value, str):
            setting_dict[target_name] = arg_value
        elif isinstance(arg_value, dict):
            try:
                setting_dict[target_name] = _fetch_setting(arg_value)  # type: ignore
            except NotImplementedError:
                warnings.warn(
                    f"Setting type for setting {arg_value} not yet implemented. "
                )
    return setting_dict