"use strict";
var __extends = (this && this.__extends) || (function() {
    var extendStatics = function(d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({
                    __proto__: []
                }
                instanceof Array && function(d, b) {
                    d.__proto__ = b;
                }) ||
            function(d, b) {
                for (var p in b)
                    if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
            };
        return extendStatics(d, b);
    };
    return function(d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);

        function __() {
            this.constructor = d;
        }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.createEmitter = exports.createCallback = exports.bound = exports.createSocketError = exports.SocketError = exports.debug = void 0;
exports.debug = createDebug();

function createDebug() {
    try {
        return require('debug')('smartsupp:client');
    } catch (_a) {
        return function() {};
    }
}
var SocketError = /** @class */ (function(_super) {
    __extends(SocketError, _super);

    function SocketError(message, context) {
        var _this = _super.call(this, message) || this;
        Object.setPrototypeOf(_this, SocketError.prototype); // fix err instanceOf
        _this.name = _this.constructor.name;
        _this.code = context.code;
        _this.type = context.type;
        _this.event = context.event;
        if (context && context.stack) {
            _this.stack = "".concat(_this.stack, "\nCaused By: ").concat(context.stack);
        }
        return _this;
    }
    return SocketError;
}(Error));
exports.SocketError = SocketError;

function createSocketError(context) {
    return new SocketError(context.message, context);
}
exports.createSocketError = createSocketError;

function bound(scope, name) {
    return function() {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        scope[name].apply(scope, args);
    };
}
exports.bound = bound;

function createCallback(resolve, reject) {
    return function(err, ret) {
        if (err) {
            reject(createSocketError(err));
        } else {
            resolve(ret);
        }
    };
}
exports.createCallback = createCallback;

function createEmitter(emitter, name) {
    return function(data) {
        emitter.emit(name, data);
    };
}
exports.createEmitter = createEmitter;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJma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