"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "ServerPublicController", {
    enumerable: true,
    get: function() {
        return ServerPublicController;
    }
});
const _awilixexpress = require("awilix-express");
const _serverconstants = require("../server.constants");
const _envutils = require("../utils/env.utils");
const _authenticate = require("../middleware/authenticate");
const _authorizationconstants = require("../constants/authorization.constants");
const _settingsstore = require("../state/settings.store");
const _serverreleaseservice = require("../services/core/server-release.service");
const _monsterpiservice = require("../services/core/monsterpi.service");
const _express = require("express");
function _ts_decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function _ts_metadata(k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
}
class ServerPublicController {
    settingsStore;
    serverVersion;
    serverReleaseService;
    monsterPiService;
    constructor(settingsStore, serverVersion, serverReleaseService, monsterPiService){
        this.settingsStore = settingsStore;
        this.serverVersion = serverVersion;
        this.serverReleaseService = serverReleaseService;
        this.monsterPiService = monsterPiService;
    }
    async welcome(req, res) {
        this.settingsStore.getSettings();
        if (!await this.settingsStore.getLoginRequired()) {
            return res.send({
                message: "Login disabled. Please load the Vue app.",
                apiDocs: "http://localhost:4000/api-docs/",
                swaggerJson: "http://localhost:4000/api-docs/swagger.json"
            });
        }
        return res.send({
            message: "Login required. Please load the Vue app.",
            apiDocs: "http://localhost:4000/api-docs/",
            swaggerJson: "http://localhost:4000/api-docs/swagger.json"
        });
    }
    getFeatures(req, res) {
        const serverSettings = this.settingsStore.getServerSettings();
        const moonrakerEnabled = serverSettings.experimentalMoonrakerSupport;
        const prusaLinkEnabled = serverSettings.experimentalPrusaLinkSupport;
        const bambuEnabled = serverSettings.experimentalBambuSupport;
        res.send({
            multiplePrinterServices: {
                available: true,
                version: 1,
                subFeatures: {
                    types: [
                        "octoprint",
                        ...moonrakerEnabled ? [
                            "klipper"
                        ] : [],
                        ...prusaLinkEnabled ? [
                            "prusaLink"
                        ] : [],
                        ...bambuEnabled ? [
                            "bambu"
                        ] : []
                    ]
                }
            }
        });
    }
    async getVersion(req, res) {
        const updateState = this.serverReleaseService.getState();
        const monsterPiVersion = this.monsterPiService.getMonsterPiVersionSafe();
        res.json({
            version: this.serverVersion,
            isNode: (0, _envutils.isNode)(),
            os: process.env.OS,
            monsterPi: monsterPiVersion,
            update: {
                synced: updateState.synced,
                updateAvailable: updateState.updateAvailable,
                airGapped: updateState.airGapped
            }
        });
    }
    async test(req, res) {
        res.send({
            message: "Test successful. Please load the Vue app."
        });
    }
}
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/"),
    (0, _awilixexpress.before)([
        (0, _authenticate.authenticate)(),
        (0, _authenticate.permission)(_authorizationconstants.PERMS.ServerInfo.Get)
    ]),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _express.Request === "undefined" ? Object : _express.Request,
        typeof _express.Response === "undefined" ? Object : _express.Response
    ]),
    _ts_metadata("design:returntype", Promise)
], ServerPublicController.prototype, "welcome", null);
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/features"),
    (0, _awilixexpress.before)([
        (0, _authenticate.authenticate)()
    ]),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _express.Request === "undefined" ? Object : _express.Request,
        typeof _express.Response === "undefined" ? Object : _express.Response
    ]),
    _ts_metadata("design:returntype", void 0)
], ServerPublicController.prototype, "getFeatures", null);
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/version"),
    (0, _awilixexpress.before)([
        (0, _authenticate.authenticate)(),
        (0, _authenticate.permission)(_authorizationconstants.PERMS.ServerInfo.Get)
    ]),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _express.Request === "undefined" ? Object : _express.Request,
        typeof _express.Response === "undefined" ? Object : _express.Response
    ]),
    _ts_metadata("design:returntype", Promise)
], ServerPublicController.prototype, "getVersion", null);
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/test"),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _express.Request === "undefined" ? Object : _express.Request,
        typeof _express.Response === "undefined" ? Object : _express.Response
    ]),
    _ts_metadata("design:returntype", Promise)
], ServerPublicController.prototype, "test", null);
ServerPublicController = _ts_decorate([
    (0, _awilixexpress.route)(_serverconstants.AppConstants.apiRoute),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _settingsstore.SettingsStore === "undefined" ? Object : _settingsstore.SettingsStore,
        String,
        typeof _serverreleaseservice.ServerReleaseService === "undefined" ? Object : _serverreleaseservice.ServerReleaseService,
        typeof _monsterpiservice.MonsterPiService === "undefined" ? Object : _monsterpiservice.MonsterPiService
    ])
], ServerPublicController);

//# sourceMappingURL=server-public.controller.js.map