"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, {
    FloorController: function() {
        return FloorController;
    },
    default: function() {
        return _default;
    }
});
const _awilixexpress = require("awilix-express");
const _authenticate = require("../middleware/authenticate");
const _serverconstants = require("../server.constants");
const _validators = require("../handlers/validators");
const _genericvalidation = require("./validation/generic.validation");
const _authorizationconstants = require("../constants/authorization.constants");
class FloorController {
    floorStore;
    isTypeormMode;
    constructor({ floorStore, isTypeormMode }){
        this.floorStore = floorStore;
        this.isTypeormMode = isTypeormMode;
    }
    async create(req, res) {
        const floor = await this.floorStore.create(req.body);
        res.send(floor);
    }
    async updateName(req, res) {
        const { id: floorId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const floor = await this.floorStore.updateName(floorId, req.body.name);
        res.send(floor);
    }
    async updateFloorNumber(req, res) {
        const { id: floorId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const floor = await this.floorStore.updateFloorNumber(floorId, req.body.floor);
        res.send(floor);
    }
    async addPrinterToFloor(req, res) {
        const { id: floorId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const floor = await this.floorStore.addOrUpdatePrinter(floorId, req.body);
        res.send(floor);
    }
    async removePrinterFromFloor(req, res) {
        const { id: floorId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const floor = await this.floorStore.removePrinter(floorId, req.body.printerId);
        res.send(floor);
    }
    async list(req, res) {
        const floors = await this.floorStore.listCache();
        res.send(floors);
    }
    async get(req, res) {
        const { id: floorId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const floor = await this.floorStore.getFloor(floorId);
        res.send(floor);
    }
    async delete(req, res) {
        const { id: floorId } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        await this.floorStore.delete(floorId);
        res.send();
    }
}
const _default = (0, _awilixexpress.createController)(FloorController).prefix(_serverconstants.AppConstants.apiRoute + "/floor").before([
    (0, _authenticate.authenticate)()
]).get("/", "list", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterFloors.List)).get("/:id", "get", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterFloors.Get)).patch("/:id/name", "updateName", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterFloors.Update)).patch("/:id/floor-number", "updateFloorNumber", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterFloors.Update)).post("/:id/printer", "addPrinterToFloor", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterFloors.Update)).delete("/:id/printer", "removePrinterFromFloor", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterFloors.Update)).delete("/:id", "delete", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterFloors.Delete)).post("/", "create", (0, _authenticate.withPermission)(_authorizationconstants.PERMS.PrinterFloors.Create));

//# sourceMappingURL=floor.controller.js.map