package xyz.stream.api.viewmodel;

import android.content.Context;
import androidx.media3.common.C;
import com.google.gson.reflect.TypeToken;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import x2.j0;
import xyz.stream.api.entity.TagsEntity;
import xyz.stream.api.entity.VideoCategoryEntity;

/* JADX INFO: loaded from: classes3.dex */
public class VideoActionViewModel extends ApiViewModel {
    private final ExecutorService executor;
    private androidx.lifecycle.w genreLiveData;
    List<Integer> ids;
    public androidx.lifecycle.v liveCollectionList;
    public androidx.lifecycle.v liveGenre;
    public androidx.lifecycle.v liveTrendingNow;
    public androidx.lifecycle.v liveVideoCategory;
    public androidx.lifecycle.v liveVideos;
    private List<TagsEntity> resultHolder;
    private final androidx.lifecycle.w videoCategoryLiveData;
    private androidx.lifecycle.w videosLiveData;

    /* JADX INFO: renamed from: xyz.stream.api.viewmodel.VideoActionViewModel$2, reason: invalid class name */
    public class AnonymousClass2 extends TypeToken<List<TagsEntity>> {
    }

    public VideoActionViewModel() {
        androidx.lifecycle.w wVar = new androidx.lifecycle.w();
        this.videoCategoryLiveData = wVar;
        this.liveVideoCategory = wVar;
        this.resultHolder = new ArrayList();
        this.ids = Arrays.asList(28, 35, 80, 18, 10749, 27, 14, 37, 53);
        this.executor = Executors.newFixedThreadPool(3);
    }

    private FutureTask<List<TagsEntity>> getGenreTask(int i10) {
        return new FutureTask<>(new xyz.stream.api.database.b(i10, 2, this));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static /* synthetic */ void lambda$getCollectionVideoList$4(int i10, int i11, int i12, androidx.lifecycle.w wVar) {
        ArrayList arrayListD = xyz.stream.api.d.b().d(i10, i11, i12);
        if (arrayListD == null) {
            arrayListD = new ArrayList();
        }
        wVar.j(arrayListD);
        xyz.stream.api.d.b().h(i10, i11, i12);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$getGenre$1(int i10) {
        FutureTask<List<TagsEntity>> genreTask = getGenreTask(i10);
        new Thread(genreTask).start();
        try {
            List<TagsEntity> list = genreTask.get();
            if (list != null && !list.isEmpty()) {
                this.genreLiveData.j(list);
                return;
            }
            postLocalGenre(i10);
        } catch (Exception unused) {
            postLocalGenre(i10);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$getGenreByIds$2(int i10) {
        FutureTask<List<TagsEntity>> genreTask = getGenreTask(i10);
        new Thread(genreTask).start();
        try {
            List<TagsEntity> list = genreTask.get();
            if (list != null && !list.isEmpty()) {
                ArrayList arrayList = new ArrayList();
                for (TagsEntity tagsEntity : list) {
                    if (this.ids.contains(tagsEntity.getId())) {
                        arrayList.add(tagsEntity);
                    }
                }
                if (arrayList.isEmpty()) {
                    this.genreLiveData.j(list);
                    return;
                } else {
                    this.genreLiveData.j(arrayList);
                    return;
                }
            }
            postLocalGenre(i10);
        } catch (Exception unused) {
            postLocalGenre(i10);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public List lambda$getGenreTask$0(int i10) throws Exception {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        xyz.stream.api.o oVarF = xyz.stream.api.o.f();
        b bVar = new b(this, countDownLatch, 3);
        oVarF.getClass();
        HashMap map = new HashMap();
        map.put("source_type", String.valueOf(i10));
        xyz.stream.api.o.g("video/tags", oVarF.n(), map, new j0(oVarF, map, bVar, i10));
        countDownLatch.await(C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS, TimeUnit.MILLISECONDS);
        return this.resultHolder;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static /* synthetic */ void lambda$getTrendingNow$3(int i10, androidx.lifecycle.w wVar) {
        ArrayList arrayListE = xyz.stream.api.d.b().e(i10);
        if (arrayListE != null && !arrayListE.isEmpty()) {
            wVar.j(arrayListE);
        }
        xyz.stream.api.d.b().j(i10);
    }

    private void postLocalGenre(int i10) {
        xyz.stream.api.f.b().f(i10, null);
        xyz.stream.api.f fVarB = xyz.stream.api.f.b();
        Map map = fVarB.f35870b;
        String strA = (map == null || !map.containsKey(String.valueOf(i10))) ? "" : xyz.stream.utils.m.a(fVarB.f35870b.get(String.valueOf(i10)));
        if (strA == null || strA.isEmpty() || strA.equals("null") || strA.equals("{}")) {
            u.a.f(this.genreLiveData);
            return;
        }
        try {
            this.genreLiveData.j((List) xyz.stream.utils.m.f36162a.fromJson(strA, new AnonymousClass2().getType()));
        } catch (Exception unused) {
            u.a.f(this.genreLiveData);
        }
    }

    public void getCollectionVideoList(int i10, int i11, int i12) {
        androidx.lifecycle.w wVar = new androidx.lifecycle.w();
        this.liveCollectionList = wVar;
        this.executor.execute(new xyz.netfly.mobile.player.f(i10, i11, i12, wVar));
    }

    public void getGenre(int i10) {
        androidx.lifecycle.w wVar = new androidx.lifecycle.w();
        this.genreLiveData = wVar;
        this.liveGenre = wVar;
        this.executor.execute(new y(this, i10, 0));
    }

    public void getGenreByIds(int i10) {
        androidx.lifecycle.w wVar = new androidx.lifecycle.w();
        this.genreLiveData = wVar;
        this.liveGenre = wVar;
        this.executor.execute(new y(this, i10, 1));
    }

    public void getTrendingNow(int i10) {
        androidx.lifecycle.w wVar = new androidx.lifecycle.w();
        this.liveTrendingNow = wVar;
        this.executor.execute(new i0.o(i10, wVar));
    }

    public void getVideoCategoryConfig(Context context) {
        String strC = xyz.stream.api.f.b().c("categories_config");
        if (strC == null || strC.isEmpty() || strC.equals("null") || strC.equals("{}")) {
            return;
        }
        try {
            this.videoCategoryLiveData.j((VideoCategoryEntity) xyz.stream.utils.m.f36162a.fromJson(strC, VideoCategoryEntity.class));
        } catch (Exception e10) {
            handleError(context, e10.getMessage());
        }
    }

    public void getVideoList(Context context, int i10, int i11, String str, String str2, String str3, String str4, int i12, String str5, int i13, int i14) {
        androidx.lifecycle.w wVar = new androidx.lifecycle.w();
        this.videosLiveData = wVar;
        this.liveVideos = wVar;
        xyz.stream.api.o.f().t(i13, i14, i10, i12, str4, str3, String.valueOf(i11), str5, str2, str, null, null, new b(this, context, 4));
    }
}
