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 = [
        "travelId"        
    ]    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "travelId+user"
    columns["moment"] = "travel//startedBy[0]//moment"
    columns["latitude"] = "travel//startedBy[0]//startPlace//latitude"
    columns["longitude"] = "travel//startedBy[0]//startPlace//longitude"
    columns["user"] = "travel//startedBy[0]//user"

    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": "StartedByAtLocation_Layer",
            "properties": [
                'UniqueID',
                'travelId',
                'moment',
                'latitude',
                'longitude',
                'user'
            ],
            "cluster_properties": [
                'latitude',
                'latitude'
            ]
        },{
            "use_case": use_case,
            "table": table_name,
            "name": "StartedByAtMoment_Layer",
            "properties": [
                'UniqueID',
                'travelId',
                'moment',
                'latitude',
                'longitude',
                'user'
            ],
            "cluster_properties": [
                'moment'
            ]
        }
    ]

    postLayersToSwagger(use_case,layers)

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