from typing import OrderedDict


def get_model_dict(obj, include_types=False):
    """Get an empty model dict or OrderedDict for an api endpoint from a complex zeep type

    'include_types' is useful for quickly determining the API endpoints expected attribute type
    (e.g. "hostName": "String128") without delving into the .xsd or API documentation.

    Note:

    some output (e.g. "ldapPortNumber": "anySimpleType") may actually be of a sub-type
    (i.e. "XInteger" in the case of "ldapPortNumber"), but this util does not yet provide that level of granularity
    in its schema inspection.

    :param obj: zeep AXL data structure
    :param include_types: (bool) replace null string with string name of AXL type for each attr
    :return: (dict or OrderedDict) of soap api endpoint
    """
    model_dict = OrderedDict()
    for e in obj.elements:
        if not hasattr(e[1].type, 'elements'):
            model_dict[e[0]] = "" if not include_types else e[1].type.name
        else:
            # list of list of elements represented as list with single ordered dict
            if hasattr(e[1].type.elements[0][1].type, 'elements'):
                model_dict[e[0]] = OrderedDict([
                    (e[1].type.elements[0][0],
                     [get_model_dict(e[1].type.elements[0][1].type,
                                     include_types=include_types)])
                ])
            else:
                model_dict[e[0]] = get_model_dict(e[1].type,
                                                  include_types=include_types)
    return model_dict