"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Domain = exports.TrackingWorkspace = exports.Query = void 0;
const integration_base_1 = require("@things-factory/integration-base");
const robotics_types_1 = require("../../../controllers/robotics-types");
exports.Query = {
    async trackingWorkspace(_, { name }, context) {
        const { domain } = context.state;
        var connection = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, name);
        if (!connection || connection.discriminator !== robotics_types_1.ROBOTICS_OBJECT_TYPES.WORKSPACE) {
            throw Error(`TrackingWorkspace '${name}' Not Found`);
        }
        return connection;
    },
    async trackingWorkspaces(_, {}, context) {
        const { domain } = context.state;
        var items = Object.keys(integration_base_1.ConnectionManager.getConnectionInstances(domain))
            .map(name => integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, name))
            .filter(connection => connection.discriminator == robotics_types_1.ROBOTICS_OBJECT_TYPES.WORKSPACE);
        return {
            items,
            total: items.length
        };
    }
};
exports.TrackingWorkspace = {
    detectionMethod(workspace) {
        var _a;
        return (_a = workspace.params) === null || _a === void 0 ? void 0 : _a.detectionMethod;
    },
    checkVideoStream(workspace) {
        var _a;
        return (_a = workspace.params) === null || _a === void 0 ? void 0 : _a.checkVideoStream;
    },
    // TODO workspace에 해당하는 데이타들만 가져와야 한다.
    async trackingCameras(workspace, _, context) {
        const { domain } = workspace;
        return Object.keys(integration_base_1.ConnectionManager.getConnectionInstances(domain))
            .map(name => integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, name))
            .filter(connection => connection.discriminator == robotics_types_1.ROBOTICS_OBJECT_TYPES.CAMERA)
            .map(connection => {
            var { handEyeConfig, handEyeMatrix, cameraCalibration, rois, camObjOffset, width, height } = connection.params || {};
            var { cameraMatrix, distortionCoefficient } = cameraCalibration || {};
            return Object.assign(Object.assign({}, connection), { cameraMatrix,
                distortionCoefficient,
                handEyeConfig,
                handEyeMatrix,
                rois,
                camObjOffset,
                width,
                height });
        });
    },
    async trackableObjects(workspace, _, context) {
        const { domain } = workspace;
        return Object.keys(integration_base_1.ConnectionManager.getConnectionInstances(domain))
            .map(name => integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, name))
            .filter(connection => connection.discriminator == robotics_types_1.ROBOTICS_OBJECT_TYPES.OBJECT)
            .map(connection => {
            var { poiOffset } = connection.params || {};
            return Object.assign(Object.assign({}, connection), { poiOffset });
        });
    },
    async robotArms(workspace, _, context) {
        const { domain } = workspace;
        return Object.keys(integration_base_1.ConnectionManager.getConnectionInstances(domain))
            .map(name => integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, name))
            .filter(connection => connection.discriminator == robotics_types_1.ROBOTICS_OBJECT_TYPES.ROBOT_ARM)
            .map(connection => {
            var { markerOffset, toolOffset } = connection.params || {};
            return Object.assign(Object.assign({}, connection), { markerOffset,
                toolOffset });
        });
    }
};
exports.Domain = {
    async trackingWorkspaces(domain) {
        return Object.keys(integration_base_1.ConnectionManager.getConnectionInstances(domain))
            .map(name => integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, name))
            .filter(connection => connection.discriminator == robotics_types_1.ROBOTICS_OBJECT_TYPES.WORKSPACE);
    }
};
//# sourceMappingURL=tracking-workspace-query.js.map