# Path: pyelt/helpers/global_helper_functions.py
# def camelcase_to_underscores(string):
#     """# example = 'CamelCase_Example'
#     # example2 = 'CamelCase_Example_AdditionalUnderscore'"""
#     string = string[0].lower() + string[1:len(string)]
# 
#     for i in string:
#         if i.isupper():
#             string = string.replace(i, '_' + i)
#     string = string.lower().replace('__', '_')
# 
#     return string


from typing import Dict, List, Union, Any
from sqlalchemy import create_engine, MetaData
from sqlalchemy.engine import reflection
from sqlalchemy.sql.sqltypes import NullType
from pyelt.helpers.global_helper_functions import camelcase_to_underscores
import time
import psycopg2
import psycopg2.extras

        class CodeableConceptColumn(Column):
            def __init__(self, name: str = '', default_value=None):
                super().__init__(name, 'text', default_value=default_value)
                # super().__init__(name, 'fhir.codeable_concept', default_value=default_value)

class FkReference:
    """Class wordt gebruikt voor foreign keys """
    def __init__(self, ref_cls: Table, fk_col: Column = None):
        self.ref_table = ref_cls
        self.fk = ''
        if fk_col:
            self.fk = fk_col.name

    def set_fk_name(self, fk):
        """wordt aangeroepen vanuit meta class. Hier wordt de fk aan de hand van de propname gemaakt."""
        if not self.fk:
            self.fk = fk



class DbFunctionParameter:
    def __init__(self, name='', type='', calling_field=''):
        self.name = name
        self.type = type
        self.calling_field = calling_field


class DbFunction:
    def __init__(self, *args):

# Path: pyelt/helpers/global_helper_functions.py
# def camelcase_to_underscores(string):
#     """# example = 'CamelCase_Example'
#     # example2 = 'CamelCase_Example_AdditionalUnderscore'"""
#     string = string[0].lower() + string[1:len(string)]
# 
#     for i in string:
#         if i.isupper():
#             string = string.replace(i, '_' + i)
#     string = string.lower().replace('__', '_')
# 
#     return string


# Path: pyelt/datalayers/database.py
from typing import Dict, List, Union, Any
from sqlalchemy import create_engine, MetaData
from sqlalchemy.engine import reflection
from sqlalchemy.sql.sqltypes import NullType
from pyelt.helpers.global_helper_functions import camelcase_to_underscores
import time
import psycopg2
import psycopg2.extras


        class CodeableConceptColumn(Column):
            def __init__(self, name: str = '', default_value=None):
                super().__init__(name, 'text', default_value=default_value)
                # super().__init__(name, 'fhir.codeable_concept', default_value=default_value)

class FkReference:
    """Class wordt gebruikt voor foreign keys """
    def __init__(self, ref_cls: Table, fk_col: Column = None):
        self.ref_table = ref_cls
        self.fk = ''
        if fk_col:
            self.fk = fk_col.name

    def set_fk_name(self, fk):
        """wordt aangeroepen vanuit meta class. Hier wordt de fk aan de hand van de propname gemaakt."""
        if not self.fk:
            self.fk = fk



class DbFunctionParameter:
    def __init__(self, name='', type='', calling_field=''):
        self.name = name
        self.type = type
        self.calling_field = calling_field


class DbFunction:
    def __init__(self, *args):

        self.name = camelcase_to_underscores(self.__class__.__name__)