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 = [
        "data",
        "extension",
        "id",
        "name",
        "publication",
        "type"   
    ]
    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "publication+id"

    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": "MediaExtension_Layer",
            "properties": [
                "UniqueID",
                "data",
                "extension",
                "id",
                "name",
                "publication",
                "type"   
                
            ],
            "cluster_properties": [
                "extension"  
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "MediaType_Layer",
            "properties": [
                "UniqueID",
                "data",
                "extension",
                "id",
                "name",
                "publication",
                "type"   
                
            ],
            "cluster_properties": [
                "type"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "MediaName_Layer",
            "properties": [
                "data",
                "extension",
                "id",
                "name",
                "publication",
                "type"   
                
            ],
            "cluster_properties": [
                "name"
            ]
        }
    ]

    postLayersToSwagger(use_case,layers)

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