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 captureCalibrateResultResolver = {
  async captureCalibrateResult(_: 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 = 'cameracalib' + ':' + name
    dataBridge.sendCmdToExt('snapshot', dataBridgeName)

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