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

export const robotArmsResolver = {
  async robotArms(_: 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.ROBOT_ARM)
      .map(connection => {
        var { markerOffset, toolOffset } = connection.params || {}

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

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