import processing.similarityFiles.similarityMain as SimilarityCalc
from db.repository import Repository

repo = Repository()


def run_similarity_calc_per_use_case():
    layers = repo.get_layers()

    # uc_layers = {}
    # for layer in layers:
    #     uc = layer.use_case
    #     if uc not in uc_layers:
    #         uc_layers[uc] = []
    #     uc_layers[uc].append(layer.layer_name)

    # for key in uc_layers:
    #     layers2 = uc_layers[key]
    #     print(f"Running for use case {key} with layers {str(layers2)}.")
    #     SimilarityCalc.main(layerNameList=layers2)

    uc_dict = dict()
    # use_case[table[layer_name]]
    for layer in layers:
        use_case = layer.use_case
        table = layer.use_case_table
        if use_case not in uc_dict:
            uc_dict[use_case] = dict()

        #aux = uc_dict[use_case]
        if table not in uc_dict[use_case]:
            uc_dict[use_case][table] = []

        uc_dict[use_case][table].append(layer.layer_name)

    for uc in uc_dict:
        for table in uc_dict[uc]:
            layers2 = uc_dict[uc][table]
            print(f"Running for use case {uc}, table {table}, with layers {str(layers2)}.")
            SimilarityCalc.main(layers2,table,uc)

    

if __name__ == '__main__':
    run_similarity_calc_per_use_case()