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

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

async function IncrementCounterReset(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 = 0
  logger.info(`incrementCount: (${connectionInstance.incrementCount})`)

  return {
    data: connectionInstance.incrementCount
  }
}

IncrementCounterReset.parameterSpec = []

IncrementCounterReset.help = 'robotics/task/increment-count-reset'

TaskRegistry.registerTaskHandler('increment-count-reset', IncrementCounterReset)
