from flask import request, Response
from db.repository import Repository
from db.entities import connected_run
import datetime
#from db.entities import clusterset #REMOVE?

repo = Repository()


def add_connected_run():
    '''
        Inserts Run with current Time into the DB
        
        :returns: Returns the _id of the connected_run entry in the DB
    
        :rtype: string
    '''    

    currentTime = datetime.datetime.now()
    runDict = {"Datetime" : str(currentTime)}
    inserted_result = repo.add_connected_run(runDict)
    return str(inserted_result.inserted_id)


def get_connected_run(): ########TODO#################
    ''' ##TODO## Gets Run from the database.

        :returns: Returns Run objects from the DB
        :rtype: Dict{_id,datetime}
    '''  
    """
    result = repo.get_connected_clusters()
    if result is None or result.retrieved == 0:        
        print("#### Response 404")
        return Response(status=404)
    else:
        return result
    conRun = ConnectedRun(result.sdfsdf)
    """

