"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Stream_1 = require("./Stream");
var MediaMetadata_1 = require("./MediaMetadata");
var Subtitle_1 = require("./Subtitle");
var PreloadedSubtitle_1 = require("../../models/PreloadedSubtitle");
var base64_js_1 = require("base64-js");
var Media = /** @class */ (function () {
    function Media(config, subtitleResolver) {
        this._config = config;
        this._subtitleResolver = subtitleResolver;
    }
    Media.prototype.getPingIntervals = function () {
        return this._config.preload.config.pingBackIntervals;
    };
    Media.prototype.isAutoPlay = function () {
        return this._config.isAutoPlay;
    };
    Media.prototype.getStartTime = function () {
        return this._config.startTime;
    };
    Media.prototype.getId = function () {
        return this._config.preload.mediaMetadata.mediaId;
    };
    Media.prototype.getMetadata = function () {
        return new MediaMetadata_1.MediaMetadata(this._config.preload.mediaMetadata);
    };
    Media.prototype.getStream = function () {
        return new Stream_1.Stream(this._config.preload.streamInfo);
    };
    Media.prototype.getNextVideoUrl = function () {
        return this._config.nextUrl;
    };
    Media.prototype.getSubtitles = function () {
        var subtitles = [];
        var preload = this._config.preload;
        var items = preload.subtitles.items;
        var preloadedData = preload.subtitle;
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.id === preloadedData.id) {
                var iv = base64_js_1.toByteArray(preloadedData.iv);
                var data = base64_js_1.toByteArray(preloadedData.data);
                var content = this._subtitleResolver.getSubtitle(preloadedData.id, iv, data);
                subtitles.push(new PreloadedSubtitle_1.PreloadedSubtitle(content, item.id, item.title, item.author, item.isDefault, item.delay));
            }
            else {
                subtitles.push(new Subtitle_1.Subtitle(this._subtitleResolver, item.url, item.id, item.title, item.author, item.isDefault, item.delay));
            }
        }
        return subtitles;
    };
    return Media;
}());
exports.Media = Media;
//# sourceMappingURL=Media.js.map