"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StudioEditionFinishedForOwner = void 0;
const tslib_1 = require("tslib");
const logger_1 = require("../../../../helpers/logger");
const constants_1 = require("../../../../initializers/constants");
const user_1 = require("../../../../models/user/user");
const user_notification_1 = require("../../../../models/user/user-notification");
const abstract_notification_1 = require("../common/abstract-notification");
class StudioEditionFinishedForOwner extends abstract_notification_1.AbstractNotification {
    prepare() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.user = yield user_1.UserModel.loadByVideoId(this.payload.id);
        });
    }
    log() {
        logger_1.logger.info('Notifying user %s its video studio edition %s is finished.', this.user.username, this.payload.url);
    }
    getSetting(user) {
        return user.NotificationSetting.myVideoStudioEditionFinished;
    }
    getTargetUsers() {
        if (!this.user)
            return [];
        return [this.user];
    }
    createNotification(user) {
        const notification = user_notification_1.UserNotificationModel.build({
            type: 19,
            userId: user.id,
            videoId: this.payload.id
        });
        notification.Video = this.payload;
        return notification;
    }
    createEmail(to) {
        const videoUrl = constants_1.WEBSERVER.URL + this.payload.getWatchStaticPath();
        return {
            to,
            subject: `Edition of your video ${this.payload.name} has finished`,
            text: `Edition of your video ${this.payload.name} has finished.`,
            locals: {
                title: 'Video edition has finished',
                action: {
                    text: 'View video',
                    url: videoUrl
                }
            }
        };
    }
}
exports.StudioEditionFinishedForOwner = StudioEditionFinishedForOwner;
//# sourceMappingURL=studio-edition-finished-for-owner.js.map