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

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

    ConnectionManager.logger.info('realsense-camera connections are ready')
  }

  async connect(connection) {
    ConnectionManager.addConnectionInstance(connection, {
      discriminator: ROBOTICS_OBJECT_TYPES.CAMERA,
      ...connection
    })

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

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

    ConnectionManager.logger.info(`realsense-camera connection(${connection.name}) is disconnected`)
  }

  trace(storage) {}
  capture() {}
  configure() {}

  get parameterSpec() {
    return [
      {
        type: 'string',
        label: 'device',
        name: 'device'
      },
      {
        type: 'entity-selector',
        label: 'base-robot-arm',
        name: 'baseRobotArm',
        property: {
          queryName: 'robotArms',
          valueKey: 'name'
        }
      },
      //   {
      //     type: 'realsense-camera-setting',
      //     label: 'setting',
      //     name: 'setting'
      //   },
      {
        type: 'camera-calibration',
        label: 'camera calibration',
        name: 'cameraCalibration'
      },
      //   {
      //     type: 'camera-roi',
      //     label: 'rois',
      //     name: 'rois'
      //   },
      {
        type: 'handeye-config',
        label: 'handeye configuration',
        name: 'handEyeConfig'
      },
      {
        type: 'handeye-calibration',
        label: 'handeye matrix',
        name: 'handEyeMatrix'
      },
      {
        type: 'offset-pose-simple',
        label: 'camera object offset',
        name: 'camObjOffset'
      }
    ]
  }

  get taskPrefixes() {
    return ['realsense']
  }

  get help() {
    return 'robotics/connector/realsense-camera'
  }
}

ConnectionManager.registerConnector('realsense-camera', new RealsenseCamera())
