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

const debug = require('debug')('aidoop:robotics:robot-arm-resolver')

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

    var connection = ConnectionManager.getConnectionInstanceByName(domain, name)

    debug('connection', connection)

    if (!connection || connection.discriminator !== ROBOTICS_OBJECT_TYPES.ROBOT_ARM) {
      debug(`RobotArm '${name}' Not Found`)
      throw Error(`RobotArm '${name}' Not Found`)
    }

    var { markerOffset, toolOffset } = connection.params || {}

    debug('result', markerOffset, toolOffset)

    return {
      ...connection,
      markerOffset,
      toolOffset
    }
  }
}
