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 "_"
    '''

    columns = [
        "connection"        
    ]    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "documents[0]//id"
    columns["database"] = "connection//database"
    columns["databaseType"] = "connection//databaseType"
    columns["host"] = "connection//host"
    columns["port"] = "connection//port"
    columns["documentCollection"] = "documents[0]//collection"
    columns["documentHash"] = "documents[0]//hash"
    columns["documentId"] = "documents[0]//id"
    
    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",                
                "documentCollection",
                "documentHash",
                "documentId"
                
                
            ],
            "cluster_properties": [
                "documentId",
                "documentCollection"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "hostAndPort_Layer",
            "properties": [
                "UniqueID",
                "database",
                "databaseType",
                "host",
                "port"                
                
            ],
            "cluster_properties": [
                "host",
                "port"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "databaseType_Layer",
            "properties": [
                "UniqueID",
                "database",
                "databaseType",
                "host",
                "port"                
                
            ],
            "cluster_properties": [
                "databaseType"
            ]
        }
    ]

    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)