import os
import sys
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.abspath(os.path.join(dir_path, "./lib")))

import libnmotion_transport_python as nmotion_transport
import inspect

def getCurrentLibraryVersion():
    return nmotion_transport.__version__

# Enums
CANBaudRate = nmotion_transport.CANBaudRate
ret_status_t = nmotion_transport.ret_status_t
ret_interface_t = nmotion_transport.ret_interface_t

# Decorator for import / export config
# def device_config(func):
#     func._device_config = True
#     return func

# import inspect

# def generate_config_map(obj):
#     cls = obj if inspect.isclass(obj) else obj.__class__
#     config = {}
#     methods = dict(inspect.getmembers(cls, inspect.isfunction))

#     for name, func in methods.items():
#         # only functions with decorator
#         if not getattr(func, "_device_config", False):
#             continue

#         if not name.startswith("get"):
#             continue

#         base = name[3:]
#         setter = f"set{base}"

#         if setter not in methods:
#             continue

#         # setter must also have decorator
#         if not getattr(methods[setter], "_device_config", False):
#             continue

#         sig = inspect.signature(methods[setter])

#         params = [
#             p.name for p in sig.parameters.values()
#             if p.name != "self"
#         ]

#         key = base[0].lower() + base[1:]

#         config[key] = {
#             "get": name,
#             "set": setter,
#             "fields": params
#         }

#     return config