"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 __());
    };
})();
var __spreadArray = (this && this.__spreadArray) || function(to, from, pack) {
    if (pack || arguments.length === 2)
        for (var i = 0, l = from.length, ar; i < l; i++) {
            if (ar || !(i in from)) {
                if (!ar) ar = Array.prototype.slice.call(from, 0, i);
                ar[i] = from[i];
            }
        }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function(mod) {
    return (mod && mod.__esModule) ? mod : {
        "default": mod
    };
};
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.SocketMock = void 0;
/* eslint-disable promise/no-callback-in-promise, promise/always-return */
var websocket_client_utils_1 = require("@smartsupp/websocket-client-utils");
var eventemitter3_1 = __importDefault(require("eventemitter3"));
var SocketMock = /** @class */ (function(_super) {
    __extends(SocketMock, _super);

    function SocketMock(options) {
        var _this = _super.call(this) || this;
        _this.options = options;
        _this.id = 'mock';
        _this.connected = false;
        _this.disconnected = true;
        _this.binaryType = 'blob';
        return _this;
    }
    SocketMock.prototype.open = function() {
        var _this = this;
        (0, websocket_client_utils_1.debug)('SocketIOMock: connect');
        this.once('visitor.connect', function(values, callback) {
            callback(null, _this.options.connectData);
        });
        this.connected = true;
        this.disconnected = false;
        this.emit('connect');
        return this;
    };
    SocketMock.prototype.close = function() {
        (0, websocket_client_utils_1.debug)('SocketIOMock: disconnect');
        this.connected = false;
        this.disconnected = false;
        this.emit('disconnect', 'io client disconnect');
        return this;
    };
    // @ts-ignore
    SocketMock.prototype.emit = function(event) {
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
        websocket_client_utils_1.debug.apply(void 0, __spreadArray(['SocketIOMock: emit'], args, false));
        if (event === 'connect' || event === 'disconnect' || event === 'visitor.connect') {
            _super.prototype.emit.apply(this, __spreadArray([event], args, false));
        } else {
            // emit to websocket is skipped
        }
        return this;
    };
    SocketMock.prototype.send = function() {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        return this.emit(event, args);
    };
    SocketMock.prototype.compress = function() {
        return this;
    };
    SocketMock.prototype.connect = function() {
        return this.open();
    };
    SocketMock.prototype.disconnect = function() {
        return this.close();
    };
    SocketMock.prototype.hasListeners = function(event) {
        return this.listenerCount(event) === 0;
    };
    SocketMock.prototype.addEventListener = function(event, fn) {
        this.addListener(event, fn);
        return this;
    };
    SocketMock.prototype.removeEventListener = function(event, fn) {
        this.removeListener(event, fn);
        return this;
    };
    return SocketMock;
}(eventemitter3_1.default));
exports.SocketMock = SocketMock;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9jay5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9tb2NrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDBFQUEwRTtBQUMxRSw0RUFBeUQ7QUFDekQsZ0VBQXdDO0FBTXhDO0lBQWdDLDhCQUFZO0lBUTNDLG9CQUNrQixPQUEwQjtRQUQ1QyxZQUdDLGlCQUFPLFNBQ1A7UUFIaUIsYUFBTyxHQUFQLE9BQU8sQ0FBbUI7UUFSckMsUUFBRSxHQUFXLE1BQU0sQ0FBQTtRQUNuQixlQUFTLEdBQVksS0FBSyxDQUFBO1FBQzFCLG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