import { ConnectionManager, Connector } from '@things-factory/integration-base'

const debug = require('debug')('aidoop:integration-base:increment-count-connector')

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

    ConnectionManager.logger.info('increment-count-connector connections are ready')
  }
  async connect(connection) {
    var { params } = connection

    var incrementCount = 0
    ConnectionManager.addConnectionInstance(connection, {
      ...connection,
      params,
      incrementCount
    })

    ConnectionManager.logger.info(
      `increment-count-connector connection(${connection.name}:${connection.endpoint}) is connected`
    )
  }

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

    ConnectionManager.logger.info(`increment-count-connector connection(${connection.name}) is disconnected`)
  }

  get parameterSpec() {
    return []
  }

  get taskPrefixes() {
    return ['increment-count']
  }

  get help() {
    return 'robotics/connector/increment-count-connector'
  }
}

ConnectionManager.registerConnector('increment-count-connector', new IncrementCountConnector())
