"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.videoWatchingValidator = void 0;
const tslib_1 = require("tslib");
const express_validator_1 = require("express-validator");
const misc_1 = require("../../../helpers/custom-validators/misc");
const logger_1 = require("../../../helpers/logger");
const shared_1 = require("../shared");
const videoWatchingValidator = [
    (0, shared_1.isValidVideoIdParam)('videoId'),
    (0, express_validator_1.body)('currentTime')
        .customSanitizer(misc_1.toIntOrNull)
        .isInt().withMessage('Should have correct current time'),
    (req, res, next) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
        logger_1.logger.debug('Checking videoWatching parameters', { parameters: req.body });
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        if (!(yield (0, shared_1.doesVideoExist)(req.params.videoId, res, 'id')))
            return;
        const user = res.locals.oauth.token.User;
        if (user.videosHistoryEnabled === false) {
            logger_1.logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id);
            return res.fail({
                status: 409,
                message: 'Video history is disabled'
            });
        }
        return next();
    })
];
exports.videoWatchingValidator = videoWatchingValidator;
//# sourceMappingURL=video-watch.js.map