"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "PrinterTagController", {
    enumerable: true,
    get: function() {
        return PrinterTagController;
    }
});
const _printertagserviceinterface = require("../services/interfaces/printer-tag.service.interface");
const _serverconstants = require("../server.constants");
const _authenticate = require("../middleware/authenticate");
const _authorizationconstants = require("../constants/authorization.constants");
const _express = require("express");
const _awilixexpress = require("awilix-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 PrinterTagController {
    printerTagService;
    constructor(printerTagService){
        this.printerTagService = printerTagService;
    }
    async listTags(req, res) {
        res.send(await this.printerTagService.listTags());
    }
    async getTagWithPrinters(req, res) {
        res.send(await this.printerTagService.getPrintersByTag(req.local.id));
    }
    async createTag(req, res) {
        if (req.body.id) {
            delete req.body.id;
        }
        const entity = await this.printerTagService.createTag(req.body);
        res.send(entity);
    }
    async updateTagName(req, res) {
        const entity = await this.printerTagService.updateTagName(req.local.id, req.body.name);
        res.send(entity);
    }
    async updateTagColor(req, res) {
        const entity = await this.printerTagService.updateTagColor(req.local.id, req.body.color);
        res.send(entity);
    }
    async deleteTag(req, res) {
        res.send(await this.printerTagService.deleteTag(req.local.id));
    }
    async addPrinterToTag(req, res) {
        const entity = await this.printerTagService.addPrinterToTag(req.local.id, req.body.printerId);
        res.send(this.printerTagService.toDto(entity));
    }
    async removePrinterFromTag(req, res) {
        res.send(await this.printerTagService.removePrinterFromTag(req.local.id, req.body.printerId));
    }
}
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/"),
    _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)
], PrinterTagController.prototype, "listTags", null);
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/:id"),
    (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)
], PrinterTagController.prototype, "getTagWithPrinters", null);
_ts_decorate([
    (0, _awilixexpress.POST)(),
    (0, _awilixexpress.route)("/"),
    _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)
], PrinterTagController.prototype, "createTag", null);
_ts_decorate([
    (0, _awilixexpress.PATCH)(),
    (0, _awilixexpress.route)("/:id/name"),
    (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)
], PrinterTagController.prototype, "updateTagName", null);
_ts_decorate([
    (0, _awilixexpress.PATCH)(),
    (0, _awilixexpress.route)("/:id/color"),
    (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)
], PrinterTagController.prototype, "updateTagColor", null);
_ts_decorate([
    (0, _awilixexpress.DELETE)(),
    (0, _awilixexpress.route)("/:id"),
    (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)
], PrinterTagController.prototype, "deleteTag", null);
_ts_decorate([
    (0, _awilixexpress.POST)(),
    (0, _awilixexpress.route)("/:id/printer"),
    (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)
], PrinterTagController.prototype, "addPrinterToTag", null);
_ts_decorate([
    (0, _awilixexpress.DELETE)(),
    (0, _awilixexpress.route)("/:id/printer"),
    (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)
], PrinterTagController.prototype, "removePrinterFromTag", null);
PrinterTagController = _ts_decorate([
    (0, _awilixexpress.route)(_serverconstants.AppConstants.apiRoute + "/printer-tag"),
    (0, _awilixexpress.before)([
        (0, _authenticate.authenticate)(),
        (0, _authenticate.authorizeRoles)([
            _authorizationconstants.ROLES.OPERATOR,
            _authorizationconstants.ROLES.ADMIN
        ])
    ]),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _printertagserviceinterface.IPrinterTagService === "undefined" ? Object : _printertagserviceinterface.IPrinterTagService
    ])
], PrinterTagController);

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