/*
 * ============================================================================
 * Copyright (C) 2017 Kaltura Inc.
 *
 * Licensed under the AGPLv3 license, unless a different license for a
 * particular library is specified in the applicable library path.
 *
 * You may obtain a copy of the License at
 * https://www.gnu.org/licenses/agpl-3.0.html
 * ============================================================================
 */

package com.kaltura.playkit;

import android.content.Context;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.util.HashMap;
import java.util.Map;

public abstract class PKPlugin {

    public interface Factory {
        String getName();

        PKPlugin newInstance();

        String getVersion();

        void warmUp(Context context);
    }

    protected abstract void onLoad(Player player, Object config, MessageBus messageBus, Context context);

    protected abstract void onUpdateMedia(PKMediaConfig mediaConfig);

    protected abstract void onUpdateConfig(Object config);

    protected abstract void onApplicationPaused();

    protected abstract void onApplicationResumed();

    protected abstract void onDestroy();

    protected PlayerEngineWrapper getPlayerEngineWrapper() {
        return null;
    }

    protected PlayerDecorator getPlayerDecorator() {
        return null;
    }

    public static JsonObject replaceKeysInPluginConfig(PKMediaEntry mediaEntry, JsonObject pluginConfig) {
        String configStr = pluginConfig.getAsJsonObject().toString();
        if (mediaEntry == null || mediaEntry.getMetadata() == null) {
            return pluginConfig;
        }
        Map<String, String> metadataMap = mediaEntry.getMetadata();
        Map<String, String> replacementMap = new HashMap<>();
        for (Map.Entry<String, String> metadataEntry : metadataMap.entrySet()) {
            replacementMap.put("\\{\\{" + metadataEntry.getKey() + "\\}\\}", metadataEntry.getValue());
        }

        for (Map.Entry<String, String> replacementEntry : replacementMap.entrySet()) {
            configStr = configStr.replaceAll(replacementEntry.getKey(), replacementEntry.getValue());
        }
        JsonParser parser = new JsonParser();
        return parser.parse(configStr).getAsJsonObject();
    }
}

@@ -1369,933 +1369,7 @@
    %7D
-%0A%0A    public static JsonObject replaceKeysInPluginConfig(PKMediaEntry mediaEntry, JsonObject pluginConfig) %7B%0A        String configStr = pluginConfig.getAsJsonObject().toString();%0A        if (mediaEntry == null %7C%7C mediaEntry.getMetadata() == null) %7B%0A            return pluginConfig;%0A        %7D%0A        Map%3CString, String%3E metadataMap = mediaEntry.getMetadata();%0A        Map%3CString, String%3E replacementMap = new HashMap%3C%3E();%0A        for (Map.Entry%3CString, String%3E metadataEntry : metadataMap.entrySet()) %7B%0A            replacementMap.put(%22%5C%5C%7B%5C%5C%7B%22 + metadataEntry.getKey() + %22%5C%5C%7D%5C%5C%7D%22, metadataEntry.getValue());%0A        %7D%0A%0A        for (Map.Entry%3CString, String%3E replacementEntry : replacementMap.entrySet()) %7B%0A            configStr = configStr.replaceAll(replacementEntry.getKey(), replacementEntry.getValue());%0A        %7D%0A        JsonParser parser = new JsonParser();%0A        return parser.parse(configStr).getAsJsonObject();%0A    %7D
 %0A%7D%0A

remove unneeded replaceKeysInPluginConfig (#543)