"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addPlaybackMetricValidator = void 0;
const tslib_1 = require("tslib");
const express_validator_1 = require("express-validator");
const metrics_1 = require("../../helpers/custom-validators/metrics");
const misc_1 = require("../../helpers/custom-validators/misc");
const config_1 = require("../../initializers/config");
const shared_1 = require("./shared");
const addPlaybackMetricValidator = [
    (0, express_validator_1.body)('resolution')
        .isInt({ min: 0 }),
    (0, express_validator_1.body)('fps')
        .optional()
        .isInt({ min: 0 }),
    (0, express_validator_1.body)('playerMode')
        .custom(metrics_1.isValidPlayerMode),
    (0, express_validator_1.body)('resolutionChanges')
        .isInt({ min: 0 }),
    (0, express_validator_1.body)('errors')
        .isInt({ min: 0 }),
    (0, express_validator_1.body)('downloadedBytesP2P')
        .isInt({ min: 0 }),
    (0, express_validator_1.body)('downloadedBytesHTTP')
        .isInt({ min: 0 }),
    (0, express_validator_1.body)('uploadedBytesP2P')
        .isInt({ min: 0 }),
    (0, express_validator_1.body)('videoId')
        .customSanitizer(misc_1.toCompleteUUID)
        .custom(misc_1.isIdOrUUIDValid),
    (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        if (!config_1.CONFIG.OPEN_TELEMETRY.METRICS.ENABLED)
            return res.sendStatus(204);
        const body = req.body;
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        if (!(yield (0, shared_1.doesVideoExist)(body.videoId, res, 'only-immutable-attributes')))
            return;
        return next();
    })
];
exports.addPlaybackMetricValidator = addPlaybackMetricValidator;
//# sourceMappingURL=metrics.js.map