"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isStudioTaskAddWatermarkValid = exports.isStudioTaskAddIntroOutroValid = exports.isStudioCutTaskValid = exports.isValidStudioTasksArray = void 0;
const tslib_1 = require("tslib");
const validator_1 = tslib_1.__importDefault(require("validator"));
const constants_1 = require("../../initializers/constants");
const video_studio_1 = require("../../lib/video-studio");
const misc_1 = require("./misc");
const videos_1 = require("./videos");
const core_utils_1 = require("../../../shared/core-utils");
function isValidStudioTasksArray(tasks) {
    if (!(0, misc_1.isArray)(tasks))
        return false;
    return tasks.length >= constants_1.CONSTRAINTS_FIELDS.VIDEO_STUDIO.TASKS.min &&
        tasks.length <= constants_1.CONSTRAINTS_FIELDS.VIDEO_STUDIO.TASKS.max;
}
exports.isValidStudioTasksArray = isValidStudioTasksArray;
function isStudioCutTaskValid(task) {
    if (task.name !== 'cut')
        return false;
    if (!task.options)
        return false;
    const { start, end } = task.options;
    if (!start && !end)
        return false;
    if (start && !validator_1.default.isInt(start + '', constants_1.CONSTRAINTS_FIELDS.VIDEO_STUDIO.CUT_TIME))
        return false;
    if (end && !validator_1.default.isInt(end + '', constants_1.CONSTRAINTS_FIELDS.VIDEO_STUDIO.CUT_TIME))
        return false;
    if (!start || !end)
        return true;
    return (0, core_utils_1.forceNumber)(start) < (0, core_utils_1.forceNumber)(end);
}
exports.isStudioCutTaskValid = isStudioCutTaskValid;
function isStudioTaskAddIntroOutroValid(task, indice, files) {
    const file = files.find(f => f.fieldname === (0, video_studio_1.buildTaskFileFieldname)(indice, 'file'));
    return (task.name === 'add-intro' || task.name === 'add-outro') &&
        file && (0, videos_1.isVideoFileMimeTypeValid)([file], null);
}
exports.isStudioTaskAddIntroOutroValid = isStudioTaskAddIntroOutroValid;
function isStudioTaskAddWatermarkValid(task, indice, files) {
    const file = files.find(f => f.fieldname === (0, video_studio_1.buildTaskFileFieldname)(indice, 'file'));
    return task.name === 'add-watermark' &&
        file && (0, videos_1.isVideoImageValid)([file], null, true);
}
exports.isStudioTaskAddWatermarkValid = isStudioTaskAddWatermarkValid;
//# sourceMappingURL=video-studio.js.map