"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TrackingWorkspaceQuery = void 0;
const type_graphql_1 = require("type-graphql");
const shell_1 = require("@things-factory/shell");
const tracking_workspace_type_1 = require("./tracking-workspace-type");
const robotics_types_1 = require("../../controllers/robotics-types");
const integration_base_1 = require("@things-factory/integration-base");
const debug = require('debug')('aidoop:robotics:tracking-workspace-query');
// extend type Query {
//   trackingWorkspaces(filters: [Filter], pagination: Pagination, sortings: [Sorting]): TrackingWorkspaceList
//   trackingWorkspace(name: String!): TrackingWorkspace
// }
let TrackingWorkspaceQuery = class TrackingWorkspaceQuery {
    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
        };
    }
    detectionMethod(trackingWorkspace) {
        var _a;
        return (_a = trackingWorkspace.params) === null || _a === void 0 ? void 0 : _a.detectionMethod;
    }
    checkVideoStream(trackingWorkspace) {
        var _a;
        return (_a = trackingWorkspace.params) === null || _a === void 0 ? void 0 : _a.checkVideoStream;
    }
    async trackingCameras(trackingWorkspace) {
        const { domain } = trackingWorkspace;
        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(trackingWorkspace) {
        const { domain } = trackingWorkspace;
        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(trackingWorkspace) {
        const { domain } = trackingWorkspace;
        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 });
        });
    }
};
__decorate([
    (0, type_graphql_1.Query)(returns => tracking_workspace_type_1.TrackingWorkspace, { description: 'To fetch a tracking workspace' }),
    __param(0, (0, type_graphql_1.Arg)('name', type => String, { nullable: false })),
    __param(1, (0, type_graphql_1.Ctx)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], TrackingWorkspaceQuery.prototype, "trackingWorkspace", null);
__decorate([
    (0, type_graphql_1.Query)(returns => tracking_workspace_type_1.TrackingWorkspaceList, { description: 'To fetch multiple tracking workspaces' }),
    __param(0, (0, type_graphql_1.Ctx)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], TrackingWorkspaceQuery.prototype, "trackingWorkspaces", null);
__decorate([
    (0, type_graphql_1.FieldResolver)(type => Boolean),
    __param(0, (0, type_graphql_1.Root)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [tracking_workspace_type_1.TrackingWorkspace]),
    __metadata("design:returntype", Boolean)
], TrackingWorkspaceQuery.prototype, "detectionMethod", null);
__decorate([
    (0, type_graphql_1.FieldResolver)(type => Boolean),
    __param(0, (0, type_graphql_1.Root)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [tracking_workspace_type_1.TrackingWorkspace]),
    __metadata("design:returntype", Boolean)
], TrackingWorkspaceQuery.prototype, "checkVideoStream", null);
__decorate([
    (0, type_graphql_1.FieldResolver)(type => shell_1.ScalarObject),
    __param(0, (0, type_graphql_1.Root)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [tracking_workspace_type_1.TrackingWorkspace]),
    __metadata("design:returntype", Promise)
], TrackingWorkspaceQuery.prototype, "trackingCameras", null);
__decorate([
    (0, type_graphql_1.FieldResolver)(type => shell_1.ScalarObject),
    __param(0, (0, type_graphql_1.Root)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [tracking_workspace_type_1.TrackingWorkspace]),
    __metadata("design:returntype", Promise)
], TrackingWorkspaceQuery.prototype, "trackableObjects", null);
__decorate([
    (0, type_graphql_1.FieldResolver)(type => shell_1.ScalarObject),
    __param(0, (0, type_graphql_1.Root)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [tracking_workspace_type_1.TrackingWorkspace]),
    __metadata("design:returntype", Promise)
], TrackingWorkspaceQuery.prototype, "robotArms", null);
TrackingWorkspaceQuery = __decorate([
    (0, type_graphql_1.Resolver)(tracking_workspace_type_1.TrackingWorkspace)
], TrackingWorkspaceQuery);
exports.TrackingWorkspaceQuery = TrackingWorkspaceQuery;
//# sourceMappingURL=%20tracking-workspace-query.js.map