"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "CameraStreamController", {
    enumerable: true,
    get: function() {
        return CameraStreamController;
    }
});
const _awilixroutercore = require("awilix-router-core");
const _serverconstants = require("../server.constants");
const _validators = require("../handlers/validators");
const _genericvalidation = require("./validation/generic.validation");
const _authenticate = require("../middleware/authenticate");
const _express = require("express");
const _authorizationconstants = require("../constants/authorization.constants");
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 CameraStreamController {
    cameraStreamService;
    isTypeormMode;
    constructor({ cameraStreamService, isTypeormMode }){
        this.cameraStreamService = cameraStreamService;
        this.isTypeormMode = isTypeormMode;
    }
    async list(req, res) {
        const result = await this.cameraStreamService.list();
        res.send(result.map((item)=>this.cameraStreamService.toDto(item)));
    }
    async get(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const result = await this.cameraStreamService.get(id);
        res.send(this.cameraStreamService.toDto(result));
    }
    async create(req, res) {
        const result = await this.cameraStreamService.create(req.body);
        res.send(this.cameraStreamService.toDto(result));
    }
    async update(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        const result = await this.cameraStreamService.update(id, req.body);
        res.send(this.cameraStreamService.toDto(result));
    }
    async delete(req, res) {
        const { id } = await (0, _validators.validateInput)(req.params, (0, _genericvalidation.idRulesV2)(this.isTypeormMode));
        await this.cameraStreamService.delete(id);
        res.send();
    }
}
_ts_decorate([
    (0, _awilixroutercore.GET)(),
    (0, _awilixroutercore.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)
], CameraStreamController.prototype, "list", null);
_ts_decorate([
    (0, _awilixroutercore.GET)(),
    (0, _awilixroutercore.route)("/: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)
], CameraStreamController.prototype, "get", null);
_ts_decorate([
    (0, _awilixroutercore.POST)(),
    (0, _awilixroutercore.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)
], CameraStreamController.prototype, "create", null);
_ts_decorate([
    (0, _awilixroutercore.PUT)(),
    (0, _awilixroutercore.route)("/: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)
], CameraStreamController.prototype, "update", null);
_ts_decorate([
    (0, _awilixroutercore.DELETE)(),
    (0, _awilixroutercore.route)("/: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)
], CameraStreamController.prototype, "delete", null);
CameraStreamController = _ts_decorate([
    (0, _awilixroutercore.route)(`${_serverconstants.AppConstants.apiRoute}/camera-stream`),
    (0, _awilixroutercore.before)([
        (0, _authenticate.authenticate)(),
        (0, _authenticate.authorizeRoles)([
            _authorizationconstants.ROLES.OPERATOR,
            _authorizationconstants.ROLES.ADMIN
        ])
    ]),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [
        Object
    ])
], CameraStreamController);

//# sourceMappingURL=camera-stream.controller.js.map