"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "PrinterMaintenanceLogController", {
    enumerable: true,
    get: function() {
        return PrinterMaintenanceLogController;
    }
});
const _awilixexpress = require("awilix-express");
const _serverconstants = require("../server.constants");
const _express = require("express");
const _authenticate = require("../middleware/authenticate");
const _authorizationconstants = require("../constants/authorization.constants");
const _printermaintenancelogservice = require("../services/orm/printer-maintenance-log.service");
const _loggerfactory = require("../handlers/logger-factory");
const _validators = require("../handlers/validators");
const _printermaintenancelogvalidation = require("../services/validators/printer-maintenance-log.validation");
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 PrinterMaintenanceLogController {
    printerMaintenanceLogService;
    logger;
    constructor(loggerFactory, printerMaintenanceLogService){
        this.printerMaintenanceLogService = printerMaintenanceLogService;
        this.logger = loggerFactory(PrinterMaintenanceLogController.name);
    }
    async list(req, res) {
        const query = await (0, _validators.validateInput)(req.query, _printermaintenancelogvalidation.getMaintenanceLogsQuerySchema);
        const result = await this.printerMaintenanceLogService.list(query);
        res.send({
            logs: result.logs.map((log)=>this.printerMaintenanceLogService.toDto(log)),
            total: result.total,
            page: query.page,
            pageSize: query.pageSize
        });
    }
    async get(req, res) {
        const logId = req.params.id;
        const log = await this.printerMaintenanceLogService.get(logId);
        res.send(this.printerMaintenanceLogService.toDto(log));
    }
    async getActiveByPrinterId(req, res) {
        const printerId = req.params.printerId;
        const log = await this.printerMaintenanceLogService.getActiveByPrinterId(printerId);
        res.send(log ? this.printerMaintenanceLogService.toDto(log) : null);
    }
    async create(req, res) {
        const data = await (0, _validators.validateInput)(req.body, _printermaintenancelogvalidation.createMaintenanceLogSchema);
        const userId = req.user?.id ?? null;
        const username = req.user?.username || "system";
        const log = await this.printerMaintenanceLogService.create(data, userId, username);
        res.send(this.printerMaintenanceLogService.toDto(log));
    }
    async complete(req, res) {
        const logId = req.params.id;
        const data = await (0, _validators.validateInput)(req.body, _printermaintenancelogvalidation.completeMaintenanceLogSchema);
        const userId = req.user?.id ?? null;
        const username = req.user?.username || "system";
        const log = await this.printerMaintenanceLogService.complete(logId, data, userId, username);
        res.send(this.printerMaintenanceLogService.toDto(log));
    }
    async delete(req, res) {
        const logId = req.params.id;
        await this.printerMaintenanceLogService.delete(logId);
        res.send({
            success: true
        });
    }
}
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.PrinterMaintenanceLog.List)
    ]),
    _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)
], PrinterMaintenanceLogController.prototype, "list", null);
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/:id"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.PrinterMaintenanceLog.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)
], PrinterMaintenanceLogController.prototype, "get", null);
_ts_decorate([
    (0, _awilixexpress.GET)(),
    (0, _awilixexpress.route)("/printer/:printerId/active"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.PrinterMaintenanceLog.Get),
        (0, _paramconvertermiddleware.ParamId)("printerId")
    ]),
    _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)
], PrinterMaintenanceLogController.prototype, "getActiveByPrinterId", null);
_ts_decorate([
    (0, _awilixexpress.POST)(),
    (0, _awilixexpress.route)("/"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.PrinterMaintenanceLog.Create)
    ]),
    _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)
], PrinterMaintenanceLogController.prototype, "create", null);
_ts_decorate([
    (0, _awilixexpress.POST)(),
    (0, _awilixexpress.route)("/:id/complete"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.PrinterMaintenanceLog.Complete),
        (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)
], PrinterMaintenanceLogController.prototype, "complete", null);
_ts_decorate([
    (0, _awilixexpress.DELETE)(),
    (0, _awilixexpress.route)("/:id"),
    (0, _awilixexpress.before)([
        (0, _authenticate.permission)(_authorizationconstants.PERMS.PrinterMaintenanceLog.Delete),
        (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)
], PrinterMaintenanceLogController.prototype, "delete", null);
PrinterMaintenanceLogController = _ts_decorate([
    (0, _awilixexpress.route)(_serverconstants.AppConstants.apiRoute + "/printer-maintenance-log"),
    (0, _awilixexpress.before)([
        (0, _authenticate.authenticate)()
    ]),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        typeof _loggerfactory.ILoggerFactory === "undefined" ? Object : _loggerfactory.ILoggerFactory,
        typeof _printermaintenancelogservice.PrinterMaintenanceLogService === "undefined" ? Object : _printermaintenancelogservice.PrinterMaintenanceLogService
    ])
], PrinterMaintenanceLogController);

//# sourceMappingURL=printer-maintenance-log.controller.js.map