"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const redis_1 = require("./redis");
const cassandra_1 = require("./cassandra");
const elastic_1 = require("./elastic");
const express_1 = require("./express");
const mysql_1 = require("./mysql");
const settings_1 = require("./settings");
const redisMock_1 = require("./mocks/redisMock");
const elasticMock_1 = require("./mocks/elasticMock");
const cassandraMock_1 = require("./mocks/cassandraMock");
const mysqlMock_1 = require("./mocks/mysqlMock");
class MockObjects {
    static makeRedis(config = {}, redisLibrary) {
        let library = redisLibrary != undefined ? redisLibrary : redisMock_1.default;
        class MockRedis extends redis_1.default {
            connect() {
                this.redis = new library();
            }
            begin_transaction() {
                if (this.redis != null)
                    return this.redis.multi();
            }
            exec_transaction(redis_transactions, callback) {
                callback(true, "1234");
            }
        }
        settings_1.default.Instance.resetRedis("mock");
        settings_1.default.Instance.setRedis("mock", config);
        return new MockRedis("mock");
    }
    static makeMysql(config = {}, mysqlLibrary) {
        let library = mysqlLibrary != undefined ? mysqlLibrary : mysqlMock_1.default;
        class MockMysql extends mysql_1.default {
            connect() {
                this.mysql = new library();
            }
        }
        settings_1.default.Instance.resetMysql("mock");
        settings_1.default.Instance.setMysql("mock", config);
        return new MockMysql("mock");
    }
    static makeElastic(config = {}, elasticLibrary) {
        let library = elasticLibrary != undefined ? elasticLibrary : elasticMock_1.default;
        class MockElastic extends elastic_1.default {
            connect() {
                this.elastic = new library({});
            }
        }
        settings_1.default.Instance.resetElastic("mock");
        settings_1.default.Instance.setElastic("mock", config);
        return new MockElastic("mock");
    }
    static makeCassandra(config = {}, cassandraLibrary) {
        let library = cassandraLibrary != undefined ? cassandraLibrary : cassandraMock_1.default;
        class MockCassandra extends cassandra_1.default {
            connect(onSuccess = null, onError = null) {
                let self = this;
                this.cassandra = new library({}, function (err) {
                    if (typeof onError == "function") {
                        onError(err);
                    }
                }, function () {
                    if (typeof onSuccess == "function") {
                        onSuccess();
                    }
                }, function (err) {
                    self.setStatus(err);
                });
            }
        }
        settings_1.default.Instance.resetCassandra("mock");
        settings_1.default.Instance.setCassandra("mock", config);
        return new MockCassandra("mock");
    }
    static makeWebServer(config) {
        class MockWebServer extends express_1.default {
            handleWriteStream(write) {
                this.logStream.write = write;
            }
            mockCustomGenerator(time, index) {
                return this.customGenerator(time, index);
            }
        }
        settings_1.default.Instance.resetSwagger("mock");
        settings_1.default.Instance.resetMorgan("mock");
        settings_1.default.Instance.setSwagger("mock", config.swagger ? config.swagger : {});
        settings_1.default.Instance.setMorgan("mock", config.morgan ? config.morgan : {});
        return new MockWebServer("mock");
    }
}
exports.default = MockObjects;
//# sourceMappingURL=mockObjects.js.map