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: split eventEpicenter
    #TODO: tags is an array, deal with arrays
    columns = [
        # "docType",
        "objecttype",
        "eventid",
        #"tags",
        "eventEpicenter", #TODO 
        "range"
    ]
    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "eventid"
    columns["firstTag"] = "tags[0]"

    table = {
        "name": table_name,
        "mappings": columns
    }

    postTableToSwagger(use_case,table)

def add_layers(use_case:str, table_name: str):
    layers = [
        {   #Useless as all objects are of the same type???
            "use_case": use_case,
            "table": table_name,
            "name": "Object_Type_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "eventid",
                "eventEpicenter",
                "range",
                "firstTag"
            ],
            "cluster_properties": [
                "objecttype"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Tag_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "eventid",
                "evenEpicenter",
                "range",
                "firstTag"
            ],
            "cluster_properties": [
                "firstTag"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Event_Epicenter_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "eventid",
                "evenEpicenter",
                "range",
                "firstTag"
            ],
            "cluster_properties": [
                "eventEpicenter"
            ]
        }
    ]

    postLayersToSwagger(use_case,layers)    

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