"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });
exports.calibrateCameraParameterResolver = void 0;
const robotics_types_1 = require("../../../controllers/robotics-types");
const integration_base_1 = require("@things-factory/integration-base");
const env_1 = require("@things-factory/env");
const await_spawn_1 = __importDefault(require("await-spawn"));
const data_bridge_manager_1 = require("../../../controllers/data-bridge/data-bridge-manager");
const visionConfig = env_1.config.get('vision', {});
const program = (_b = (_a = visionConfig.camera) === null || _a === void 0 ? void 0 : _a.cameraCalibrator) === null || _b === void 0 ? void 0 : _b.program;
exports.calibrateCameraParameterResolver = {
    async calibrateCameraParameter(_, { name }, context) {
        const { domain } = context.state;
        var camera = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, name);
        if (!camera || camera.discriminator !== robotics_types_1.ROBOTICS_OBJECT_TYPES.CAMERA) {
            throw Error(`Tracking Camera '${name}' Not Found`);
        }
        let activeApp = data_bridge_manager_1.DataBridgeConnectionManager.getActive();
        if (activeApp === '' || activeApp === name) {
            // TODO: control to run multiple python applications here
            data_bridge_manager_1.DataBridgeConnectionManager.set(name, 'start');
        }
        var executable = program[0];
        var params = [...program.slice(1), name];
        var cameraParameter = await (0, await_spawn_1.default)(executable, params);
        env_1.logger.info(`calibration matrix:\n'${cameraParameter === null || cameraParameter === void 0 ? void 0 : cameraParameter.toString()}'`);
        return JSON.parse(cameraParameter.toString());
    }
};
//# sourceMappingURL=calibrate-camera-parameter-resolver.js.map