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 = [
        "brand",
        "carLicensePlate",        
        "colour",
        "deleted",
        "model",
        "numberOfEvaluations",
        "observations",        
        "ownerId",
        "seats",
        "state",       
        "sumOfEvaluations"
        "year"

    ]
    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "carLicensePlate"

    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": "GeneralCar_layer",
            "properties": [
                "UniqueID",
                "brand",
                "carLicensePlate",        
                "colour",
                "deleted",
                "model",
                "numberOfEvaluations",
                "observations",        
                "ownerId",
                "seats",
                "state",       
                "sumOfEvaluations"
                "year"                            
            ],
            "cluster_properties": [
                "brand",
                "model",
                "seats",
                "year",
                "ownerId",
                "state"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Owner_layer",
            "properties": [
                "UniqueID",
                "brand",
                "carLicensePlate",        
                "colour",
                "deleted",
                "model",
                "numberOfEvaluations",
                "observations",        
                "ownerId",
                "seats",
                "state",       
                "sumOfEvaluations"
                "year"                               
            ],
            "cluster_properties": [
                "OwnerID",
                "UniqueID"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "CarAge_layer",
            "properties": [
                "UniqueID",
                "brand",
                "carLicensePlate",        
                "colour",
                "deleted",
                "model",
                "numberOfEvaluations",
                "observations",        
                "ownerId",
                "seats",
                "state",       
                "sumOfEvaluations"
                "year"                                     
            ],
            "cluster_properties": [
                "year",
                "state"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Model_layer",
            "properties": [
                "UniqueID",
                "brand",
                "carLicensePlate",        
                "colour",
                "deleted",
                "model",
                "numberOfEvaluations",
                "observations",        
                "ownerId",
                "seats",
                "state",       
                "sumOfEvaluations"
                "year"                                    
            ],
            "cluster_properties": [
                "brand",
                "model",
                "seats"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "CarState_layer",
            "properties": [
                "UniqueID",
                "ownerId",
                "deleted",
                "state"                                
            ],
            "cluster_properties": [
                "deleted",
                "state" 
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "CarEvaluation_layer",
            "properties": [
                "UniqueID",
                "brand",     
                "colour",
                "deleted",
                "model",
                "numberOfEvaluations",
                "observations",        
                "ownerId",
                "seats",
                "state",       
                "sumOfEvaluations"
                "year"                                 
            ],
            "cluster_properties": [
                "numberOfEvaluations",
                "sumOfEvaluations" 
            ]
        }
    ]

    postLayersToSwagger(use_case,layers)    

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