"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "PrinterSettingsController", {
    enumerable: true,
    get: function() {
        return PrinterSettingsController;
    }
});
const _awilixexpress = require("awilix-express");
const _authenticate = require("../middleware/authenticate");
const _serverconstants = require("../server.constants");
const _authorizationconstants = require("../constants/authorization.constants");
const _octoprintclient = require("../services/octoprint/octoprint.client");
const _printercache = require("../state/printer.cache");
const _express = require("express");
const _paramconvertermiddleware = require("../middleware/param-converter.middleware");
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 PrinterSettingsController {
    printerCache;
    octoprintClient;
    constructor(printerCache, octoprintClient){
        this.printerCache = printerCache;
        this.octoprintClient = octoprintClient;
    }
    async get(req, res) {
        const loginDto = await this.printerCache.getLoginDtoAsync(req.local.id);
        const settings = await this.octoprintClient.getSettings(loginDto);
        res.send(settings.data);
    }
    async syncPrinterName(req, res) {
        const printerLogin = await this.printerCache.getLoginDtoAsync(req.local.id);
        const name = await this.printerCache.getNameAsync(req.local.id);
        const settings = await this.octoprintClient.updatePrinterNameSetting(printerLogin, name);
        res.send(settings.data);
    }
}
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/:id"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.PrinterSettings.Get),
        (0, _paramconvertermiddleware.ParamId)("id")
    ]),
    _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)
], PrinterSettingsController.prototype, "get", null);
_ts_decorate([
    (0, _awilixexpress.POST)(),
    (0, _awilixexpress.route)("/:id/sync-printername"),
    (0, _awilixexpress.before)([
        (0, _paramconvertermiddleware.ParamId)("id")
    ]),
    _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)
], PrinterSettingsController.prototype, "syncPrinterName", null);
PrinterSettingsController = _ts_decorate([
    (0, _awilixexpress.route)(_serverconstants.AppConstants.apiRoute + "/printer-settings"),
    (0, _awilixexpress.before)([
        (0, _authenticate.authenticate)()
    ]),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _printercache.PrinterCache === "undefined" ? Object : _printercache.PrinterCache,
        typeof _octoprintclient.OctoprintClient === "undefined" ? Object : _octoprintclient.OctoprintClient
    ])
], PrinterSettingsController);

//# sourceMappingURL=printer-settings.controller.js.map