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 = [
        
        "carLicensePlate",
        "carOwner",
        "depositBalance",
        "endDate",
        "id",
        "observations",
        "offerId",
        "priceBalance",
        "rentForTime",
        "rewardBalance",
        "seats",
        "startDate",
        "status",
        "totalPrice",
        
    ]    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "id"
    columns["endPlaceAddress"] = "endPlace//address"
    columns["endPlaceLatitude"] = "endPlace//latitude"
    columns["endPlaceLongitude"] = "endPlace//longitude"
    columns["startPlaceAddress"] = "startPlace//address"
    columns["startPlaceLatitude"] = "startPlace//latitude"
    columns["startPlaceLongitude"] = "startPlace//longitude"
    columns["checkedByUser"] = "checkedBy[0]//user"
    columns["checkedByMoment"] = "checkedBy[0]//moment"
    columns["checkedByLatitude"] = "checkedBy[0]//coordinate//latitude"
    columns["checkedByLongitude"] = "checkedBy[0]//coordinate//longitude"
    columns["checkedByState"] = "checkedBy[0]//state"
    columns["scoreNumber"] = "score//length"
    columns["scoreSum"] = "score//sum"

    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": "StartingPoint_Layer",
            "properties": [
                'UniqueID',
                'startPlaceLatitude',
                'startPlaceLongitude',
                'startDate',
                'endDate'
            ],
            "cluster_properties": [
                'startPlaceLatitude',
                'startPlaceLatitude'
            ]
        },{
            "use_case": use_case,
            "table": table_name,
            "name": "StartingTime_Layer",
            "properties": [
                'UniqueID',
                'startDate',
                'endDate'
            ],
            "cluster_properties": [
                'startDate'
            ]
        },{
            "use_case": use_case,
            "table": table_name,
            "name": "CheckedByLocation_Layer", 
            "properties": [
                'UniqueID',
                'checkedByUser',
                'checkedByMoment',
                'checkedByLatitude',
                'checkedByLongitude',
                'checkedByState',
                'startPlaceLatitude',
                'startPlaceLongitude'
                
            ],
            "cluster_properties": [
                'checkedByLatitude',
                'checkedByLongitude'
            ]
        },{
            "use_case": use_case,
            "table": table_name,
            "name": "CheckedByMoment_Layer", 
            "properties": [
                'UniqueID',
                'checkedByUser',
                'checkedByMoment',
                'checkedByLatitude',
                'checkedByLongitude',
                'checkedByState',
                'startDate',
                'startPlaceLatitude',
                'startPlaceLongitude'
                
                
            ],
            "cluster_properties": [
                'checkedByMoment',
                'startDate'
            ]
        },{
            "use_case": use_case,
            "table": table_name,
            "name": "FinishedTime_Layer", 
            "properties": [
                'UniqueID',
                'startDate',
                'endDate'
            ],
            "cluster_properties": [
                'endDate'
            ]
        },{
            "use_case": use_case,
            "table": table_name,
            "name": "Price_Layer",
            "properties": [
                'UniqueID',
                'totalPrice',
                'priceBalance',
                'depositBalance',
                'rewardBalance'
            ],
            "cluster_properties": [
                'totalPrice',
                'priceBalance',
                'depositBalance',
                'rewardBalance'
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Status_Layer",
            "properties": [
                'UniqueID',              
                'status',
                'rentForTime'
            ],
            "cluster_properties": [
                'status',
                'rentForTime'
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Score_Layer",
            "properties": [
                'UniqueID',              
                'scoreSum',
                'scoreNumber'
            ],
            "cluster_properties": [
                'scoreSum',
                'scoreNumber'
            ]
        }
    ]

    postLayersToSwagger(use_case,layers)

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