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

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

    var connection = ConnectionManager.getConnectionInstance(domain, name)
    if (!connection || connection.discriminator !== ROBOTICS_OBJECT_TYPES.OBJECT) {
      throw Error(`TrackableObject '${name}' Not Found`)
    }

    connection.state = state

    return {
      ...connection
    }
  }
}
