"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidPlaylistIdParam = exports.isValidVideoIdParam = exports.areValidationErrors = void 0;
const express_validator_1 = require("express-validator");
const misc_1 = require("../../../helpers/custom-validators/misc");
const logger_1 = require("../../../helpers/logger");
function areValidationErrors(req, res, options = {}) {
    const { omitLog = false, omitBodyLog = false, tags = [] } = options;
    if (!omitLog) {
        logger_1.logger.debug('Checking %s - %s parameters', req.method, req.originalUrl, {
            body: omitBodyLog
                ? 'omitted'
                : req.body,
            params: req.params,
            query: req.query,
            files: req.files,
            tags
        });
    }
    const errors = (0, express_validator_1.validationResult)(req);
    if (!errors.isEmpty()) {
        logger_1.logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() });
        res.fail({
            message: 'Incorrect request parameters: ' + Object.keys(errors.mapped()).join(', '),
            instance: req.originalUrl,
            data: {
                'invalid-params': errors.mapped()
            }
        });
        return true;
    }
    return false;
}
exports.areValidationErrors = areValidationErrors;
function isValidVideoIdParam(paramName) {
    return (0, express_validator_1.param)(paramName)
        .customSanitizer(misc_1.toCompleteUUID)
        .custom(misc_1.isIdOrUUIDValid).withMessage('Should have a valid video id (id, short UUID or UUID)');
}
exports.isValidVideoIdParam = isValidVideoIdParam;
function isValidPlaylistIdParam(paramName) {
    return (0, express_validator_1.param)(paramName)
        .customSanitizer(misc_1.toCompleteUUID)
        .custom(misc_1.isIdOrUUIDValid).withMessage('Should have a valid playlist id (id, short UUID or UUID)');
}
exports.isValidPlaylistIdParam = isValidPlaylistIdParam;
//# sourceMappingURL=utils.js.map