from _add_use_case_scripts.requestPost import postLayersToSwagger, postTableToSwagger

def add_table(use_case: str, table_name: str):
    '''
    take the columns and add the mappings at the server
    replace all "/"'s in the internal representation with a "_"
    '''

    # TODO Manuel: check back with alex

    use_case = "car-sharing"
    columns = [
        # "docType",
        "documents",
        "connection"
    ]
    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "documents[0]//id"

    columns["document1id"] = "documents[0]//id"
    columns["document1collection"] = "documents[0]//collection"
    columns["document1hash"] = "documents[0]//hash"

    columns["databaseType"] = "connection//databaseType"
    columns["database"] = "connection//database"
    columns["host"] = "connection//host"
    columns["port"] = "connection//port"
    columns["username"] = "connection//username"
    columns["password"] = "connection//password"
    
    table = {
        "name": table_name,
        "mappings": columns
    }

    postTableToSwagger(use_case,table)

def add_layers(use_case:str, table_name: str):
    layers = [
        {
            "use_case": use_case,
            "table": table_name,
            "name": "document_layer",
            "properties": [
                "UniqueID",
                "document1id",
                "document1collection",
                "document1hash"
                
                
            ],
            "cluster_properties": [
                ##TODO discuss with other to see if we keep them?
                "document1id",
                "document1collection"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "connection_layer",
            "properties": [
                "UniqueID",
                "username",
                "password"
                
                
            ],
            "cluster_properties": [
                ##TODO discuss with other to see if we keep them?
                "username"
            ]
        }
    ]

    postLayersToSwagger(use_case,layers)

def main(use_case: str):
    print("HASH")
    table_name = "hash"
    add_table(use_case,table_name)
    add_layers(use_case,table_name)