"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, {
    PrinterSettingsController: function() {
        return PrinterSettingsController;
    },
    default: function() {
        return _default;
    }
});
const _awilixexpress = require("awilix-express");
const _authenticate = require("../middleware/authenticate");
const _validators = require("../handlers/validators");
const _serverconstants = require("../server.constants");
const _genericvalidation = require("./validation/generic.validation");
const _printersettingscontrollervalidation = require("./validation/printer-settings-controller.validation");
const _authorizationconstants = require("../constants/authorization.constants");
class PrinterSettingsController {
    printerCache;
    octoprintClient;
    isTypeormMode;
    constructor({ printerCache, octoprintClient, isTypeormMode }){
        this.printerCache = printerCache;
        this.octoprintClient = octoprintClient;
        this.isTypeormMode = isTypeormMode;
    }
    async get(req, res) {
        const { id: printerId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const loginDto = await this.printerCache.getLoginDtoAsync(printerId);
        const settings = await this.octoprintClient.getSettings(loginDto);
        res.send(settings);
    }
    async setGCodeAnalysis(req, res) {
        const { id: printerId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const { enabled } = await (0, _validators.validateMiddleware)(req, _printersettingscontrollervalidation.setGcodeAnalysis);
        const printerLogin = await this.printerCache.getLoginDtoAsync(printerId);
        const settings = await this.octoprintClient.setGCodeAnalysis(printerLogin, enabled);
        res.send(settings);
    }
    async syncPrinterName(req, res) {
        const { id: printerId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const printerLogin = await this.printerCache.getLoginDtoAsync(printerId);
        const name = await this.printerCache.getNameAsync(printerId);
        const settings = await this.octoprintClient.updatePrinterNameSetting(printerLogin, name);
        res.send(settings);
    }
}
const _default = (0, _awilixexpress.createController)(PrinterSettingsController).prefix(_serverconstants.AppConstants.apiRoute + "/printer-settings").before([
    (0, _authenticate.authenticate)()
]).get("/:id", "get", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterSettings.Get)).post("/:id/gcode-analysis", "setGCodeAnalysis").post("/:id/sync-printername", "syncPrinterName");

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