"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.api = void 0;
const debug_1 = __importDefault(require("debug"));
const robotics_types_1 = require("../robotics-types");
const integration_base_1 = require("@things-factory/integration-base");
const debug = (0, debug_1.default)('aidoop:robotics:robot-arm-api-decorator');
const api = (target, property, descriptor) => {
    const method = descriptor.value;
    descriptor.value = async function (domain, robotArmName, ...params) {
        const RobotArmAPI = this;
        const connection = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, robotArmName);
        debug('connection', robotArmName, connection);
        if (!connection || connection.discriminator !== robotics_types_1.ROBOTICS_OBJECT_TYPES.ROBOT_ARM) {
            debug(`RobotArm '${robotArmName}' Not Found`);
            throw Error(`RobotArm '${robotArmName}' Not Found`);
        }
        var { platform } = connection;
        var { apis } = RobotArmAPI.getPlatform(platform);
        var m = apis[method.name];
        if (!m) {
            throw Error(`RobotArm Platform '${platform}' doesn't have API ${method.name}`);
        }
        const result = await m.call(this, connection, ...params);
        debug('api', domain.subdomain, robotArmName, method.name, params, result);
        return result;
    };
    return descriptor;
};
exports.api = api;
//# sourceMappingURL=decorators.js.map