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

const debug = require('debug')('aidoop:robotics:increment-count-tick')

async function IncrementCounterTick(step, { logger, domain, closures, state }) {
  var { connection } = step

  var connectionInstance = ConnectionManager.getConnectionInstanceByName(domain, connection)
  if (!connectionInstance) {
    throw Error(`connection is not found : ${connectionInstance}`)
  }

  connectionInstance.incrementCount += 1
  logger.info(`incrementCount: (${connectionInstance.incrementCount})`)

  return {
    data: connectionInstance.incrementCount
  }
}

IncrementCounterTick.parameterSpec = []

IncrementCounterTick.help = 'robotics/task/increment-count-tick'

TaskRegistry.registerTaskHandler('increment-count-tick', IncrementCounterTick)
