from flask import request, Response
from db.repository import Repository

repo = Repository()

def get_conn_clusters():
    ''' Gets connected_clusters from the database.

        :returns: Returns similarity objects from the DB
        :rtype: Dict
    '''  
    result = repo.get_connected_clusters()
    if result is None or len(result) == 0:        
        print("MongoDb Get Error: Response 404")
        return Response(status=404)
    else:

        return result

def get_conn_clusters_use_case(use_case):
    ''' Gets connected_clusters from the database.

        :returns: Returns similarity objects from the DB
        :rtype: Dict
    '''  
    result = repo.get_connected_clusters_for_use_case(use_case)
    if result is None or len(result) == 0:        
        print("MongoDb Get Error: Response 404")
        return Response(status=404)
    else:

        return result

def get_conn_clusters_table(use_case,table):
    ''' Gets connected_clusters from the database.

        :returns: Returns similarity objects from the DB
        :rtype: Dict
    '''  
    result = repo.get_connected_clusters_for_table(use_case, table)
    if result is None or len(result) == 0:        
        print("MongoDb Get Error: Response 404")
        return Response(status=404)
    else:

        return result

def get_conn_clusters_name(use_case,table,layer_name):
    ''' Gets connected_clusters from the database.

        :returns: Returns similarity objects from the DB
        :rtype: Dict
    '''  
    result = repo.get_connected_clusters_by_name(use_case,table,layer_name)
    if result is None or len(result) == 0:        
        print("MongoDb Get Error: Response 404")
        return Response(status=404)
    else:

        return result
