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

export const finishHandeyeCalibrateResolver = {
  async finishHandeyeCalibrate(_: any, { name }, context: any) {
    const { domain } = context.state

    var camera = ConnectionManager.getConnectionInstanceByName(domain, name)
    if (!camera || camera.discriminator !== ROBOTICS_OBJECT_TYPES.CAMERA) {
      throw Error(`Tracking Camera '${name}' Not Found`)
    }

    var dataBridgeName = 'handeyecalib' + ':' + name
    dataBridge.sendCmdToExt('exit', dataBridgeName)

    // TODO: check if this kina return value is available
    return true
  }
}
