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 = [
        # "docType",
        "objecttype",
        "videoid",
        "duration",
        "price",
        "creator",
        "creationTimestamp",
        #"tags",
        "geolocation",
        "eventid",
        "lastupdate",
        "md5",
        "informativeRating",
        "impactRating",
        "trustinessRating",
        "ready",
        "path",
        "preview",
        #"thumbnails" #not important?

    ]
    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "videoid"
    columns["encodedAudio"] = "codec//audio"
    columns["encodedVideo"] = "codec//video"
    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 Classification?
            "use_case": use_case,
            "table": table_name,
            "name": "Object_Type_Layer",
            "properties": [
                "objecttype",
                "videoid",
                "duration",
                "price",
                "creator",
                "creationTimestamp",
                "lastupdate",
                "firstTag"
            ],
            "cluster_properties": [
                "objecttype"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Price_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "creationTimestamp",
                "geolocation",
                "videoid",
                "price",
                "informativeRating",
                "impactRating",
                "trustinessRating",
                "firstTag"
            ],
            "cluster_properties": [
                "price"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Tag_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "creationTimestamp",
                "geolocation",
                "videoid",
                "price",
                "informativeRating",
                "impactRating",
                "trustinessRating",
                "firstTag"
            ],
            "cluster_properties": [
                "firstTag"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Informative_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "creationTimestamp",
                "geolocation",
                "videoid",
                "price",
                "informativeRating",
                "impactRating",
                "trustinessRating",
                "firstTag"
            ],
            "cluster_properties": [
                "informativeRating"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Impact_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "creationTimestamp",
                "geolocation",
                "videoid",
                "price",
                "informativeRating",
                "impactRating",
                "trustinessRating",
                "firstTag"
            ],
            "cluster_properties": [
                "impactRating"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Trust_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "creationTimestamp",
                "geolocation",
                "videoid",
                "price",
                "informativeRating",
                "impactRating",
                "trustinessRating",
                "firstTag"
            ],
            "cluster_properties": [
                "trustinessRating"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Location_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "creationTimestamp",
                "geolocation",
                "videoid",
                "price",
                "informativeRating",
                "impactRating",
                "trustinessRating",
                "firstTag"
            ],
            "cluster_properties": [
                "geolocation"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Video_Age_Layer",
            "properties": [
                "UniqueID",
                "objecttype",
                "creationTimestamp",
                "geolocation",
                "videoid",
                "price",
                "informativeRating",
                "impactRating",
                "trustinessRating",
                "firstTag"
            ],
            "cluster_properties": [
                "creationTimestamp"
            ]
        }
    ]

    postLayersToSwagger(use_case,layers)    

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