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

export const trackingCamerasResolver = {
  async trackingCameras(_: any, {}, context: any) {
    const { domain } = context.state

    var items = Object.keys(ConnectionManager.getConnectionInstances(domain))
      .map(name => ConnectionManager.getConnectionInstanceByName(domain, name))
      .filter(connection => connection.discriminator == ROBOTICS_OBJECT_TYPES.CAMERA)
      .map(connection => {
        var { handEyeConfig, handEyeMatrix, cameraCalibration, rois, camObjOffset, width, height } =
          connection.params || {}
        var { cameraMatrix, distortionCoefficient } = cameraCalibration || {}

        return {
          ...connection,
          cameraMatrix,
          distortionCoefficient,
          handEyeConfig,
          handEyeMatrix,
          rois,
          camObjOffset,
          width,
          height
        }
      })

    return {
      items,
      total: items.length
    }
  }
}
