package xyz.stream.api;

import com.google.gson.Gson;
import java.io.File;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executors;

/* JADX INFO: loaded from: classes3.dex */
public final class f {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static f f35868c;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Map f35869a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Map f35870b;

    public static f b() {
        if (f35868c == null) {
            f35868c = new f();
        }
        return f35868c;
    }

    public final boolean a(String str) {
        Object obj;
        String strC = c("adult_premium_config");
        if (strC != null && !strC.isEmpty()) {
            try {
                Map map = (Map) xyz.stream.utils.m.f36162a.fromJson(strC, new CmsConfigHelper$2().getType());
                if (map != null && map.containsKey(str) && (obj = map.get(str)) != null && (obj instanceof Number)) {
                    return ((Number) obj).intValue() == 1;
                }
            } catch (Exception e10) {
                u.a.g(e10, new StringBuilder("Error parsing adult config: "));
            }
        }
        return false;
    }

    public final String c(String str) {
        Map map = this.f35869a;
        return (map == null || !map.containsKey(str)) ? "" : xyz.stream.utils.m.a(this.f35869a.get(str));
    }

    public final String d() {
        if (this.f35869a == null) {
            e(null);
        }
        try {
            Map map = this.f35869a;
            if (map == null || !map.containsKey("pay_website_config")) {
                return "";
            }
            Object obj = this.f35869a.get("pay_website_config");
            Gson gson = xyz.stream.utils.m.f36162a;
            Map map2 = (Map) gson.fromJson(gson.toJsonTree(obj), new CmsConfigHelper$7().getType());
            return (map2 == null || !map2.containsKey("netfly")) ? "" : (String) ((Map) gson.fromJson(gson.toJsonTree(map2.get("netfly")), new CmsConfigHelper$8().getType())).get("link_url");
        } catch (Exception e10) {
            u.a.g(e10, new StringBuilder("Error getting pay website config: "));
            return "";
        }
    }

    public final void e(String str) {
        try {
            File file = new File(xyz.stream.utils.e.d().f36112a.getFilesDir(), "cms_config.json");
            if (str != null && !str.isEmpty() && !str.equals("null") && !str.equals("{}")) {
                file.delete();
                kotlinx.coroutines.flow.h.R(file, str);
            } else if (!file.exists()) {
                kotlinx.coroutines.flow.h.c(xyz.stream.utils.e.d().f36112a, "cms_config.json", file.getAbsolutePath());
            }
            if (file.exists()) {
                this.f35869a = (Map) xyz.stream.utils.m.f36162a.fromJson(kotlinx.coroutines.flow.h.K(file), new CmsConfigHelper$1().getType());
                String strC = c("subtitle_language");
                String strC2 = c("audio_language");
                String strC3 = c("subtitle_audio");
                xyz.stream.utils.o oVarC = xyz.stream.utils.o.c();
                oVarC.getClass();
                Executors.newSingleThreadExecutor().execute(new androidx.media3.exoplayer.audio.j(oVarC, strC, strC2, strC3, 11));
            }
        } catch (Exception e10) {
            u.a.g(e10, new StringBuilder("Error initializing CMS config: "));
        }
    }

    public final void f(int i10, String str) {
        try {
            File file = new File(xyz.stream.utils.e.d().f36112a.getFilesDir(), "cms_genre.json");
            if (str != null && !str.isEmpty() && !str.equals("null") && !str.equals("{}")) {
                String strK = kotlinx.coroutines.flow.h.K(file);
                Type type = new CmsConfigHelper$4().getType();
                Gson gson = xyz.stream.utils.m.f36162a;
                Map map = (Map) gson.fromJson(strK, type);
                this.f35870b = map;
                if (map == null || !map.containsKey(String.valueOf(i10))) {
                    if (this.f35870b == null) {
                        this.f35870b = new HashMap();
                    }
                    this.f35870b.put(String.valueOf(i10), gson.fromJson(str, Object.class));
                    kotlinx.coroutines.flow.h.R(file, xyz.stream.utils.m.a(this.f35870b));
                    return;
                }
                if (Objects.equals(xyz.stream.utils.m.a(this.f35870b.get(String.valueOf(i10))), str)) {
                    return;
                }
                this.f35870b.put(String.valueOf(i10), gson.fromJson(str, Object.class));
                kotlinx.coroutines.flow.h.R(file, xyz.stream.utils.m.a(this.f35870b));
                return;
            }
            if (!file.exists()) {
                kotlinx.coroutines.flow.h.c(xyz.stream.utils.e.d().f36112a, "cms_genre.json", file.getAbsolutePath());
            }
            this.f35870b = (Map) xyz.stream.utils.m.f36162a.fromJson(kotlinx.coroutines.flow.h.K(file), new CmsConfigHelper$3().getType());
        } catch (Exception e10) {
            u.a.g(e10, new StringBuilder("Error initializing genre config: "));
        }
    }
}
