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 = [
        'videoId',
        'objType', 
        'eventName',
        'video_token', 
        'replyTo', 
        'created', 
        'duration', 
        'videoResolution', 
        'label', 
        'threadId', 
        'position', 
        'views', 
        'moderatedBy', 
        'moderationDate', 
        'communityManagerNotes', 
        'rewards', 
        'video_state', 
        'video_type'
    ]
    
    columns = { c : c for c in columns }
    columns["UniqueID"] = "videoId"
    columns["moderatedBy"] = "enum(moderatedBy)"
    columns["video_state"] = "enum(video_state)"
    columns["video_type"] = "enum(video_type)"
    columns["videoResolution"] = "enum(videoResolution)"

    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": "Manager_Layer",
            "properties": [
                "UniqueID",
                "moderationDate",
                "moderatedBy",
                "video_state",
                "video_type"
            ],
            "cluster_properties": [
                "moderatedBy",
                "video_state"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Video_Popularity_Layer",
            "properties": [
                "UniqueID",
                "label",
                "created",
                "views",
                "rewards",
                "video_state",
                "video_type"
            ],
            "cluster_properties": [
                "views",
                "video_type"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Video_Age_Layer",
            "properties": [
                "UniqueID",
                "label",
                "created",
                "views",
                "rewards",
                "video_state",
                "video_type"
            ],
            "cluster_properties": [
                "created"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Rewards_Layer",
            "properties": [
                "UniqueID",
                "label",
                "created",
                "views",
                "rewards",
                "video_state",
                "video_type"
            ],
            "cluster_properties": [
                "rewards"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Video_Lenght_Layer",
            "properties": [
                "UniqueID",
                "created",
                "views",
                "duration",
                "video_state",
                "video_type"
            ],
            "cluster_properties": [
                "duration"
            ]
        },
        {
            "use_case": use_case,
            "table": table_name,
            "name": "Video_Resolution_Layer",
            "properties": [
                "UniqueID",
                "created",
                "views",
                "videoResolution",
                "video_state",
                "video_type"
            ],
            "cluster_properties": [
                "videoResolution"
            ]
        }
    ]

    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)