import { Domain } from '@things-factory/shell'
import { ConnectionManager } from '@things-factory/integration-base'
import { ROBOTICS_OBJECT_TYPES } from '../../controllers/robotics-types'

export function getTrackingWorkspace(domain: Domain) {
  var connectionNames = Object.keys(ConnectionManager.getConnectionInstances(domain))

  var candidateName = connectionNames.find(
    name => ConnectionManager.getConnectionInstanceByName(domain, name).discriminator == ROBOTICS_OBJECT_TYPES.WORKSPACE
  )

  return candidateName && ConnectionManager.getConnectionInstanceByName(domain, candidateName)
}
