"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, {
    PrinterGroupController: function() {
        return PrinterGroupController;
    },
    default: function() {
        return _default;
    }
});
const _awilixexpress = require("awilix-express");
const _serverconstants = require("../server.constants");
const _authenticate = require("../middleware/authenticate");
const _authorizationconstants = require("../constants/authorization.constants");
const _validators = require("../handlers/validators");
const _genericvalidation = require("./validation/generic.validation");
class PrinterGroupController {
    printerGroupService;
    isTypeormMode;
    constructor({ printerGroupService, isTypeormMode }){
        this.printerGroupService = printerGroupService;
        this.isTypeormMode = isTypeormMode;
    }
    async listGroups(req, res) {
        res.send(await this.printerGroupService.listGroups());
    }
    async getGroup(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        res.send(await this.printerGroupService.getGroupWithPrinters(id));
    }
    async createGroup(req, res) {
        const entity = await this.printerGroupService.createGroup(req.body);
        res.send(entity);
    }
    async updateGroupName(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const entity = await this.printerGroupService.updateGroupName(id, req.body.name);
        res.send(entity);
    }
    async deleteGroup(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        res.send(await this.printerGroupService.deleteGroup(id));
    }
    async addPrinterToGroup(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const entity = await this.printerGroupService.addPrinterToGroup(id, req.body.printerId);
        res.send(this.printerGroupService.toDto(entity));
    }
    async removePrinterFromGroup(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        res.send(await this.printerGroupService.removePrinterFromGroup(id, req.body.printerId));
    }
}
const _default = (0, _awilixexpress.createController)(PrinterGroupController).prefix(_serverconstants.AppConstants.apiRoute + "/printer-group").before([
    (0, _authenticate.authenticate)(),
    (0, _authenticate.authorizeRoles)([
        _authorizationconstants.ROLES.OPERATOR,
        _authorizationconstants.ROLES.ADMIN
    ])
]).get("/", "listGroups").post("/", "createGroup").get("/:id", "getGroup").delete("/:id", "deleteGroup").patch("/:id/name", "updateGroupName").post("/:id/printer", "addPrinterToGroup").delete("/:id/printer", "removePrinterFromGroup");

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