"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    config: function() {
        return config;
    },
    configureContainer: function() {
        return configureContainer;
    }
});
const _axios = /*#__PURE__*/ _interop_require_default(require("axios"));
const _simplegit = /*#__PURE__*/ _interop_require_default(require("simple-git"));
const _octokit = require("octokit");
const _awilix = require("awilix");
const _toadscheduler = require("toad-scheduler");
const _containertokens = require("./container.tokens");
const _printerservice = require("./services/mongoose/printer.service");
const _printerservice1 = require("./services/orm/printer.service");
const _settingsstore = require("./state/settings.store");
const _settingsservice = require("./services/mongoose/settings.service");
const _serverreleaseservice = require("./services/core/server-release.service");
const _taskmanagerservice = require("./services/core/task-manager.service");
const _serverupdateservice = require("./services/core/server-update.service");
const _githubservice = require("./services/core/github.service");
const _filecache = require("./state/file.cache");
const _printerwebsockettask = require("./tasks/printer-websocket.task");
const _socketiotask = require("./tasks/socketio.task");
const _socketfactory = require("./services/socket.factory");
const _printerfilesstore = require("./state/printer-files.store");
const _eventemitter = require("./handlers/event-emitter");
const _serverconstants = require("./server.constants");
const _softwareupdatetask = require("./tasks/software-update.task");
const _loggerfactory = require("./handlers/logger-factory");
const _multerservice = require("./services/core/multer.service");
const _fileuploadtrackercache = require("./state/file-upload-tracker.cache");
const _serverhost = require("./server.host");
const _boottask = require("./tasks/boot.task");
const _userservice = require("./services/mongoose/user.service");
const _userservice1 = require("./services/orm/user.service");
const _roleservice = require("./services/mongoose/role.service");
const _roleservice1 = require("./services/orm/role.service");
const _tasks = require("./tasks");
const _permissionservice = require("./services/mongoose/permission.service");
const _permissionservice1 = require("./services/orm/permission.service");
const _printerfilecleantask = require("./tasks/printer-file-clean.task");
const _authorizationconstants = require("./constants/authorization.constants");
const _customgcodeservice = require("./services/mongoose/custom-gcode.service");
const _customgcodeservice1 = require("./services/orm/custom-gcode.service");
const _printerwebsocketrestoretask = require("./tasks/printer-websocket-restore.task");
const _pluginfirmwareupdateservice = require("./services/octoprint/plugin-firmware-update.service");
const _pluginrepositorycache = require("./services/octoprint/plugin-repository.cache");
const _cachemanager = require("./handlers/cache-manager");
const _influxdbv2baseservice = require("./services/influxdb-v2/influx-db-v2-base.service");
const _configservice = require("./services/core/config.service");
const _printcompletionsocketiotask = require("./tasks/print-completion.socketio.task");
const _printcompletionservice = require("./services/mongoose/print-completion.service");
const _printcompletionservice1 = require("./services/orm/print-completion.service");
const _socketiogateway = require("./state/socket-io.gateway");
const _clientbundleservice = require("./services/core/client-bundle.service");
const _floorservice = require("./services/mongoose/floor.service");
const _floorstore = require("./state/floor.store");
const _yamlservice = require("./services/core/yaml.service");
const _monsterpiservice = require("./services/core/monsterpi.service");
const _batchcallservice = require("./services/core/batch-call.service");
const _clientbundletask = require("./tasks/client-bundle.task");
const _octoprintwebsocketadapter = require("./services/octoprint/octoprint-websocket.adapter");
const _printercache = require("./state/printer.cache");
const _printersocketstore = require("./state/printer-socket.store");
const _testprintersocketstore = require("./state/test-printer-socket.store");
const _printereventscache = require("./state/printer-events.cache");
const _logsmanagerservice = require("./services/core/logs-manager.service");
const _camerastreamservice = require("./services/mongoose/camera-stream.service");
const _camerastreamservice1 = require("./services/orm/camera-stream.service");
const _jwtservice = require("./services/authentication/jwt.service");
const _authservice = require("./services/authentication/auth.service");
const _refreshtokenservice = require("./services/mongoose/refresh-token.service");
const _pluginthrottling = require("@octokit/plugin-throttling");
const _refreshtokenservice1 = require("./services/orm/refresh-token.service");
const _settingsservice1 = require("./services/orm/settings.service");
const _floorservice1 = require("./services/orm/floor.service");
const _floorpositionservice = require("./services/orm/floor-position.service");
const _typeormservice = require("./services/typeorm/typeorm.service");
const _userroleservice = require("./services/orm/user-role.service");
const _printergroupservice = require("./services/orm/printer-group.service");
const _moonrakerclient = require("./services/moonraker/moonraker.client");
const _moonrakerwebsocketadapter = require("./services/moonraker/moonraker-websocket.adapter");
const _octoprintapi = require("./services/octoprint.api");
const _octoprintclient = require("./services/octoprint/octoprint.client");
const _moonrakerapi = require("./services/moonraker.api");
const _printerapifactory = require("./services/printer-api.factory");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function config(key, experimentalMode, serviceTypeorm, serviceMongoose) {
    return {
        [key]: experimentalMode ? serviceTypeorm : serviceMongoose
    };
}
function configureContainer(isSqlite = false) {
    const container = (0, _awilix.createContainer)({
        injectionMode: _awilix.InjectionMode.PROXY
    });
    const di = _containertokens.DITokens;
    container.register({
        [di.serverTasks]: (0, _awilix.asValue)(_tasks.ServerTasks),
        [di.isTypeormMode]: (0, _awilix.asValue)(isSqlite),
        [di.appDefaultRole]: (0, _awilix.asValue)(_authorizationconstants.ROLES.GUEST),
        [di.appDefaultRoleNoLogin]: (0, _awilix.asValue)(_authorizationconstants.ROLES.ADMIN),
        [di.serverVersion]: (0, _awilix.asFunction)(()=>{
            return process.env[_serverconstants.AppConstants.VERSION_KEY];
        }),
        [di.socketFactory]: (0, _awilix.asClass)(_socketfactory.SocketFactory).transient(),
        ...config(di.typeormService, isSqlite, (0, _awilix.asClass)(_typeormservice.TypeormService).singleton(), (0, _awilix.asValue)(null)),
        ...config(di.settingsService, isSqlite, (0, _awilix.asClass)(_settingsservice1.SettingsService2), (0, _awilix.asClass)(_settingsservice.SettingsService)),
        ...config(di.floorService, isSqlite, (0, _awilix.asClass)(_floorservice1.FloorService).singleton(), (0, _awilix.asClass)(_floorservice.FloorService).singleton()),
        ...config(di.floorPositionService, isSqlite, (0, _awilix.asClass)(_floorpositionservice.FloorPositionService).singleton(), (0, _awilix.asValue)(null)),
        ...config(di.cameraStreamService, isSqlite, (0, _awilix.asClass)(_camerastreamservice1.CameraStreamService).singleton(), (0, _awilix.asClass)(_camerastreamservice.CameraStreamService).singleton()),
        ...config(di.printerService, isSqlite, (0, _awilix.asClass)(_printerservice1.PrinterService), (0, _awilix.asClass)(_printerservice.PrinterService)),
        ...config(di.printerGroupService, isSqlite, (0, _awilix.asClass)(_printergroupservice.PrinterGroupService), (0, _awilix.asValue)(null)),
        ...config(di.refreshTokenService, isSqlite, (0, _awilix.asClass)(_refreshtokenservice1.RefreshTokenService).singleton(), (0, _awilix.asClass)(_refreshtokenservice.RefreshTokenService).singleton()),
        ...config(di.userService, isSqlite, (0, _awilix.asClass)(_userservice1.UserService).singleton(), (0, _awilix.asClass)(_userservice.UserService).singleton()),
        ...config(di.userRoleService, isSqlite, (0, _awilix.asClass)(_userroleservice.UserRoleService).singleton(), (0, _awilix.asValue)(null)),
        ...config(di.roleService, isSqlite, (0, _awilix.asClass)(_roleservice1.RoleService).singleton(), (0, _awilix.asClass)(_roleservice.RoleService).singleton()),
        ...config(di.permissionService, isSqlite, (0, _awilix.asClass)(_permissionservice1.PermissionService).singleton(), (0, _awilix.asClass)(_permissionservice.PermissionService).singleton()),
        ...config(di.customGCodeService, isSqlite, (0, _awilix.asClass)(_customgcodeservice1.CustomGcodeService).singleton(), (0, _awilix.asClass)(_customgcodeservice.CustomGcodeService).singleton()),
        ...config(di.printCompletionService, isSqlite, (0, _awilix.asClass)(_printcompletionservice1.PrintCompletionService).singleton(), (0, _awilix.asClass)(_printcompletionservice.PrintCompletionService).singleton()),
        [di.serverHost]: (0, _awilix.asClass)(_serverhost.ServerHost).singleton(),
        [di.settingsStore]: (0, _awilix.asClass)(_settingsstore.SettingsStore).singleton(),
        [di.configService]: (0, _awilix.asClass)(_configservice.ConfigService),
        [di.authService]: (0, _awilix.asClass)(_authservice.AuthService).singleton(),
        [di.jwtService]: (0, _awilix.asClass)(_jwtservice.JwtService).singleton(),
        [di.loggerFactory]: (0, _awilix.asFunction)(_loggerfactory.LoggerFactory).transient(),
        [di.taskManagerService]: (0, _awilix.asClass)(_taskmanagerservice.TaskManagerService).singleton(),
        [di.toadScheduler]: (0, _awilix.asClass)(_toadscheduler.ToadScheduler).singleton(),
        [di.eventEmitter2]: (0, _awilix.asFunction)(_eventemitter.configureEventEmitter).singleton(),
        [di.cacheManager]: (0, _awilix.asFunction)(_cachemanager.configureCacheManager).singleton(),
        [di.serverReleaseService]: (0, _awilix.asClass)(_serverreleaseservice.ServerReleaseService).singleton(),
        [di.monsterPiService]: (0, _awilix.asClass)(_monsterpiservice.MonsterPiService).singleton(),
        [di.serverUpdateService]: (0, _awilix.asClass)(_serverupdateservice.ServerUpdateService).singleton(),
        [di.githubService]: (0, _awilix.asClass)(_githubservice.GithubService),
        [di.octokitService]: (0, _awilix.asFunction)((cradle)=>{
            const config = cradle.configService;
            const CustomOctoKit = _octokit.Octokit.plugin(_pluginthrottling.throttling);
            return new CustomOctoKit({
                auth: config.get(_serverconstants.AppConstants.GITHUB_PAT),
                throttle: {
                    onRateLimit: (retryAfter, options, octokit, retryCount)=>{
                        const logger = (0, _loggerfactory.LoggerFactory)()("OctoKitThrottle");
                        logger.warn(`Request quota exhausted for request ${options.method} ${options.url}`);
                    },
                    onSecondaryRateLimit: (retryAfter, options, octokit)=>{
                        const logger = (0, _loggerfactory.LoggerFactory)()("OctoKitThrottle");
                        logger.warn(`SecondaryRateLimit detected for request ${options.method} ${options.url}`);
                    }
                }
            });
        }),
        [di.clientBundleService]: (0, _awilix.asClass)(_clientbundleservice.ClientBundleService),
        [di.logDumpService]: (0, _awilix.asClass)(_logsmanagerservice.LogDumpService),
        [di.simpleGitService]: (0, _awilix.asValue)((0, _simplegit.default)()),
        [di.httpClient]: (0, _awilix.asValue)(_axios.default.create({
            maxBodyLength: 1000 * 1000 * 1000,
            maxContentLength: 1000 * 1000 * 1000
        })),
        [di.socketIoGateway]: (0, _awilix.asClass)(_socketiogateway.SocketIoGateway).singleton(),
        [di.multerService]: (0, _awilix.asClass)(_multerservice.MulterService).singleton(),
        [di.yamlService]: (0, _awilix.asClass)(_yamlservice.YamlService),
        [di.printerLogin]: (0, _awilix.asValue)(null),
        [di.printerApiFactory]: (0, _awilix.asClass)(_printerapifactory.PrinterApiFactory).transient(),
        [di.octoprintApi]: (0, _awilix.asClass)(_octoprintapi.OctoprintApi).transient(),
        [di.octoprintClient]: (0, _awilix.asClass)(_octoprintclient.OctoprintClient).singleton(),
        [di.octoPrintSockIoAdapter]: (0, _awilix.asClass)(_octoprintwebsocketadapter.OctoprintWebsocketAdapter).transient(),
        [di.moonrakerApi]: (0, _awilix.asClass)(_moonrakerapi.MoonrakerApi).transient(),
        [di.moonrakerClient]: (0, _awilix.asClass)(_moonrakerclient.MoonrakerClient).singleton(),
        [di.moonrakerWebsocketAdapter]: (0, _awilix.asClass)(_moonrakerwebsocketadapter.MoonrakerWebsocketAdapter).transient(),
        [di.batchCallService]: (0, _awilix.asClass)(_batchcallservice.BatchCallService).singleton(),
        [di.pluginFirmwareUpdateService]: (0, _awilix.asClass)(_pluginfirmwareupdateservice.PluginFirmwareUpdateService).singleton(),
        [di.floorStore]: (0, _awilix.asClass)(_floorstore.FloorStore).singleton(),
        [di.pluginRepositoryCache]: (0, _awilix.asClass)(_pluginrepositorycache.PluginRepositoryCache).singleton(),
        [di.fileCache]: (0, _awilix.asClass)(_filecache.FileCache).singleton(),
        [di.fileUploadTrackerCache]: (0, _awilix.asClass)(_fileuploadtrackercache.FileUploadTrackerCache).singleton(),
        [di.printerFilesStore]: (0, _awilix.asClass)(_printerfilesstore.PrinterFilesStore).singleton(),
        [di.printerCache]: (0, _awilix.asClass)(_printercache.PrinterCache).singleton(),
        [di.printerEventsCache]: (0, _awilix.asClass)(_printereventscache.PrinterEventsCache).singleton(),
        [di.printerSocketStore]: (0, _awilix.asClass)(_printersocketstore.PrinterSocketStore).singleton(),
        [di.testPrinterSocketStore]: (0, _awilix.asClass)(_testprintersocketstore.TestPrinterSocketStore).singleton(),
        [di.influxDbV2BaseService]: (0, _awilix.asClass)(_influxdbv2baseservice.InfluxDbV2BaseService),
        [di.bootTask]: (0, _awilix.asClass)(_boottask.BootTask),
        [di.softwareUpdateTask]: (0, _awilix.asClass)(_softwareupdatetask.SoftwareUpdateTask),
        [di.socketIoTask]: (0, _awilix.asClass)(_socketiotask.SocketIoTask).singleton(),
        [di.clientDistDownloadTask]: (0, _awilix.asClass)(_clientbundletask.ClientDistDownloadTask).singleton(),
        [di.printCompletionSocketIoTask]: (0, _awilix.asClass)(_printcompletionsocketiotask.PrintCompletionSocketIoTask).singleton(),
        [di.printerWebsocketTask]: (0, _awilix.asClass)(_printerwebsockettask.PrinterWebsocketTask).singleton(),
        [di.printerWebsocketRestoreTask]: (0, _awilix.asClass)(_printerwebsocketrestoretask.PrinterWebsocketRestoreTask).singleton(),
        [di.printerFileCleanTask]: (0, _awilix.asClass)(_printerfilecleantask.PrinterFileCleanTask).singleton()
    });
    return container;
}

//# sourceMappingURL=container.js.map