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

export class MarkedObject implements Connector {
  async ready(connectionConfigs) {
    await Promise.all(connectionConfigs.map(this.connect.bind(this)))

    ConnectionManager.logger.info('marked-object connections are ready')
  }

  async connect(connection) {
    // var { params } = connection

    ConnectionManager.addConnectionInstance(connection, {
      discriminator: ROBOTICS_OBJECT_TYPES.OBJECT,
      ...connection
    })

    ConnectionManager.logger.info(`marked-object connection(${connection.name}:${connection.endpoint}) is connected`)
  }

  async disconnect(connection) {
    ConnectionManager.removeConnectionInstance(connection)

    ConnectionManager.logger.info(`marked-object connection(${connection.name}) is disconnected`)
  }

  get parameterSpec() {
    return [
      {
        type: 'string',
        label: 'type',
        name: 'type'
      },
      {
        type: 'offset-pose-simple',
        label: 'poi-offset',
        name: 'poiOffset'
      }
    ]
  }

  get taskPrefixes() {
    return ['trackable-object']
  }

  get help() {
    return 'robotics/connector/marked-object'
  }
}

ConnectionManager.registerConnector('marked-object', new MarkedObject())
