from flask import request, Response
from db.repository import Repository
from routes.connRun import add_connected_run
from processing.similarityFiles.miscFunctions import *

repo = Repository()


def add_conn_clusters(inputDict,runId):
    ''' Stores connected_clusters in the database.

    :param Dict() inputDict: Contains the data to insert

    :param string runId: Id of the Run 

    ''' 
    
    outputJSON = convertLayerDictToJSON(inputDict,runId)
    repo.add_connected_clusters(outputJSON)


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
