"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const integration_base_1 = require("@things-factory/integration-base");
const utils_1 = require("@things-factory/utils");
const get_tracking_workspace_1 = require("./get-tracking-workspace");
const debug = require('debug')('aidoop:robotics:ws-get-object-state');
async function TrackingWorkspaceGetObjectState(step, { logger, data, domain }) {
    var { connection, params: { accessor } } = step;
    var object = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connection) || {};
    if (!object) {
        throw new Error(`no connection : ${connection}`);
    }
    var endpoint = accessor ? (0, utils_1.access)(accessor, data) : {};
    logger.info(`accessor: ${accessor}, endpoint: ${endpoint}`);
    var workspace = (0, get_tracking_workspace_1.getTrackingWorkspace)(domain);
    var { engine } = workspace;
    var { trackingStorage } = engine;
    var objectState = trackingStorage.getObjectState(endpoint);
    // test if pose is available or return null
    if (isNaN(objectState.pose.x) ||
        isNaN(objectState.pose.y) ||
        isNaN(objectState.pose.z) ||
        isNaN(objectState.pose.u) ||
        isNaN(objectState.pose.v) ||
        isNaN(objectState.pose.w))
        objectState = null;
    return {
        data: objectState
    };
}
TrackingWorkspaceGetObjectState.parameterSpec = [
    {
        type: 'scenario-step-input',
        label: 'accessor',
        name: 'accessor'
    }
];
TrackingWorkspaceGetObjectState.help = 'robotics/task/tracking-workspace-get-object-state';
integration_base_1.TaskRegistry.registerTaskHandler('tracking-ws-get-object-state', TrackingWorkspaceGetObjectState);
//# sourceMappingURL=tracking-workspace-get-object-state.js.map