"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const integration_base_1 = require("@things-factory/integration-base");
const utils_1 = require("@things-factory/utils");
var scenarioQueues = {};
async function PushQueue(step, { logger, data }) {
    var { params: { queueName, queueCount, accessor } } = step;
    if (scenarioQueues[queueName] == undefined) {
        scenarioQueues[queueName] = [];
    }
    var queueData = accessor ? (0, utils_1.access)(accessor, data) : {};
    console.log('queueData: ', queueData);
    scenarioQueues[queueName].push(queueData);
    if (scenarioQueues[queueName].length > queueCount) {
        scenarioQueues[queueName].shift(queueCount - scenarioQueues[queueName].length);
    }
    console.log('scenarioQueues[queueName]: ', scenarioQueues[queueName]);
    return {
        data: scenarioQueues[queueName]
    };
}
async function ClearQueue(step, { logger, data }) {
    var { params: { queueName, queueCount, accessor } } = step;
    if (scenarioQueues[queueName] == undefined) {
        scenarioQueues[queueName] = [];
    }
    scenarioQueues[queueName] = [];
    return {
        data: scenarioQueues[queueName]
    };
}
PushQueue.parameterSpec = [
    {
        type: 'string',
        label: 'queue-name',
        name: 'queueName'
    },
    {
        type: 'number',
        label: 'queue-count',
        name: 'queueCount'
    },
    {
        type: 'scenario-step-input',
        label: 'accessor',
        name: 'accessor'
    }
];
ClearQueue.parameterSpec = [
    {
        type: 'string',
        label: 'queue-name',
        name: 'queueName'
    }
];
PushQueue.connectorFree = true;
PushQueue.help = 'robotics/task/push-queue';
ClearQueue.connectorFree = true;
ClearQueue.help = 'robotics/task/push-queue';
integration_base_1.TaskRegistry.registerTaskHandler('push-queue', PushQueue);
integration_base_1.TaskRegistry.registerTaskHandler('clear-queue', ClearQueue);
//# sourceMappingURL=push-queue.js.map