/**
 * gcode api
 */
let _gCodeEngine = null;

const getObjectForNA = function () {
    const _sys = bl.getSystemInfoSync() || { platform: '' };
    if (_gCodeEngine !== null) return _gCodeEngine;
    if (_sys.platform.toLowerCase() === 'android') {
        _gCodeEngine = global.getGCodeEngine();
    } else {
        _gCodeEngine = global.BLGlobal.getGCodeEngine();
    }
    return _gCodeEngine;
};
/**
 * 调用客户端的方法需要绑定一下作用域，因为客户端注入的方法是没有作用域的
 * */
export default {
    generateGrayscaleBuffer: function (imageData, width, height) {
        let _obj = getObjectForNA();
        if (_obj) {
            return _obj.generateGrayscaleBuffer.call(_obj, imageData, width, height);
        } else {
            throw new Error('当前环境不支持gCode');
        }
    },
    generateBlackMatrix: function (imageData, width, height) {
        let _obj = getObjectForNA();
        if (_obj) {
            return _obj.generateBlackMatrix.call(_obj, imageData, width, height);
        } else {
            throw new Error('当前环境不支持gCode');
        }
    },
    reedSolomonDecode: function (bits, size, twoS) {
        let _obj = getObjectForNA();
        if (_obj) {
            return _obj.reedSolomonDecode.call(_obj, bits, size, twoS);
        } else {
            throw new Error('当前环境不支持gCode');
        }
    },
    decode: function (imageBuffer, width, height) {
        let _obj = getObjectForNA();
        if (_obj) {
            return _obj.decode.call(_obj, imageBuffer, width, height);
        } else {
            throw new Error('当前环境不支持gCode');
        }
    }
};
