"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.doesCommentIdExist = exports.doesVideoCommentExist = exports.doesVideoCommentThreadExist = void 0;
const tslib_1 = require("tslib");
const video_comment_1 = require("../../../models/video/video-comment");
const core_utils_1 = require("../../../../shared/core-utils");
function doesVideoCommentThreadExist(idArg, video, res) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const id = (0, core_utils_1.forceNumber)(idArg);
        const videoComment = yield video_comment_1.VideoCommentModel.loadById(id);
        if (!videoComment) {
            res.fail({
                status: 404,
                message: 'Video comment thread not found'
            });
            return false;
        }
        if (videoComment.videoId !== video.id) {
            res.fail({
                type: "comment_not_associated_to_video",
                message: 'Video comment is not associated to this video.'
            });
            return false;
        }
        if (videoComment.inReplyToCommentId !== null) {
            res.fail({ message: 'Video comment is not a thread.' });
            return false;
        }
        res.locals.videoCommentThread = videoComment;
        return true;
    });
}
exports.doesVideoCommentThreadExist = doesVideoCommentThreadExist;
function doesVideoCommentExist(idArg, video, res) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const id = (0, core_utils_1.forceNumber)(idArg);
        const videoComment = yield video_comment_1.VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id);
        if (!videoComment) {
            res.fail({
                status: 404,
                message: 'Video comment thread not found'
            });
            return false;
        }
        if (videoComment.videoId !== video.id) {
            res.fail({
                type: "comment_not_associated_to_video",
                message: 'Video comment is not associated to this video.'
            });
            return false;
        }
        res.locals.videoCommentFull = videoComment;
        return true;
    });
}
exports.doesVideoCommentExist = doesVideoCommentExist;
function doesCommentIdExist(idArg, res) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const id = (0, core_utils_1.forceNumber)(idArg);
        const videoComment = yield video_comment_1.VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id);
        if (!videoComment) {
            res.fail({
                status: 404,
                message: 'Video comment thread not found'
            });
            return false;
        }
        res.locals.videoCommentFull = videoComment;
        return true;
    });
}
exports.doesCommentIdExist = doesCommentIdExist;
//# sourceMappingURL=video-comments.js.map