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 = [
        "available",
        "deleted",
        "deposit",
        "endDate",
        "id",
        "priceForKm",
        "priceForTime",
        "startDate"
    ]
    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "id"
    columns["carID"] = "car//carLicensePlate"
    columns["carOwner"] = "car//ownerId"
    columns["startPlaceAddress"] = "startPlace//address"
    columns["startPlaceLatitude"] = "startPlace//latitude"
    columns["startPlaceLongitude"] = "startPlace//longitude"

    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": "OfferStartPlace_layer",
            "properties": [
                "UniqueID",
                "carID",
                "carOwner", 
                "startPlaceAddress",
                "startPlaceLatitude",
                "startPlaceLongitude",
                "startDate"

            ],
            "cluster_properties": [
                "carOwner",
                "startPlaceLatitude",
                "startPlaceLongitude"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "OfferedCar_layer",
            "properties": [
                "UniqueID",
                "carID",
                "carOwner"

            ],
            "cluster_properties": [
                "carID",
                "carOwner"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "OfferPrice_layer",
            "properties": [
                "UniqueID",
                "carOwner",
                "priceForKm",
                "priceForTime",
                "deposit"
            ],
            "cluster_properties": [
                "carOwner",
                "priceForKm",
                "priceForTime",
                "deposit"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "OfferTime_layer",
            "properties": [
                "UniqueID",
                "carOwner",
                "startDate",
                "endDate"

            ],
            "cluster_properties": [
                "carOwner",
                "startDate",
                "endDate"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "OfferStatus_layer",
            "properties": [
                "UniqueID",
                "carOwner",
                "available",
                "deleted"

            ],
            "cluster_properties": [
                "carOwner",
                "available",
                "deleted"
            ]
        }
    ]

    postLayersToSwagger(use_case,layers)

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