"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.myVideoPlaylistsRouter = void 0;
const tslib_1 = require("tslib");
const express_1 = tslib_1.__importDefault(require("express"));
const core_utils_1 = require("../../../../shared/core-utils");
const extra_utils_1 = require("../../../../shared/extra-utils");
const middlewares_1 = require("../../../middlewares");
const video_playlists_1 = require("../../../middlewares/validators/videos/video-playlists");
const video_playlist_1 = require("../../../models/video/video-playlist");
const myVideoPlaylistsRouter = express_1.default.Router();
exports.myVideoPlaylistsRouter = myVideoPlaylistsRouter;
myVideoPlaylistsRouter.get('/me/video-playlists/videos-exist', middlewares_1.authenticate, video_playlists_1.doVideosInPlaylistExistValidator, (0, middlewares_1.asyncMiddleware)(doVideosInPlaylistExist));
function doVideosInPlaylistExist(req, res) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const videoIds = req.query.videoIds.map(i => (0, core_utils_1.forceNumber)(i));
        const user = res.locals.oauth.token.User;
        const results = yield video_playlist_1.VideoPlaylistModel.listPlaylistSummariesOf(user.Account.id, videoIds);
        const existObject = {};
        for (const videoId of videoIds) {
            existObject[videoId] = [];
        }
        for (const result of results) {
            for (const element of result.VideoPlaylistElements) {
                existObject[element.videoId].push({
                    playlistElementId: element.id,
                    playlistId: result.id,
                    playlistDisplayName: result.name,
                    playlistShortUUID: (0, extra_utils_1.uuidToShort)(result.uuid),
                    startTimestamp: element.startTimestamp,
                    stopTimestamp: element.stopTimestamp
                });
            }
        }
        return res.json(existObject);
    });
}
//# sourceMappingURL=my-video-playlists.js.map