package xyz.stream.api.viewmodel;

import androidx.media3.exoplayer.upstream.CmcdConfiguration;
import com.google.android.gms.measurement.internal.u1;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import xyz.stream.api.entity.LiveChannelEntity;
import xyz.stream.api.entity.TagLiveEntity;

/* JADX INFO: loaded from: classes3.dex */
public abstract class BaseLiveViewModel extends ApiViewModel {
    protected final androidx.lifecycle.w allChannelLiveData;
    protected final androidx.lifecycle.w bannerLiveData;
    protected final androidx.lifecycle.w categoryLiveData;
    protected final androidx.lifecycle.w collectionLiveData;
    protected final androidx.lifecycle.w firstCollectionLiveData;
    public final androidx.lifecycle.v liveAllChannel;
    public final androidx.lifecycle.v liveBanner;
    public final androidx.lifecycle.v liveCategory;
    public final androidx.lifecycle.v liveCollection;
    public final androidx.lifecycle.v liveFirstCollection;
    public final androidx.lifecycle.v liveSearch;
    protected final androidx.lifecycle.w searchLiveData;
    private final ExecutorService executor = Executors.newFixedThreadPool(10);
    private final AtomicInteger propertiesRequestVersion = new AtomicInteger();
    private final AtomicInteger categoryRequestVersion = new AtomicInteger();
    private final AtomicInteger liveChannelRequestVersion = new AtomicInteger();
    private final AtomicInteger searchRequestVersion = new AtomicInteger();

    public BaseLiveViewModel() {
        androidx.lifecycle.w wVar = new androidx.lifecycle.w();
        this.allChannelLiveData = wVar;
        this.liveAllChannel = wVar;
        androidx.lifecycle.w wVar2 = new androidx.lifecycle.w();
        this.categoryLiveData = wVar2;
        this.liveCategory = wVar2;
        androidx.lifecycle.w wVar3 = new androidx.lifecycle.w();
        this.searchLiveData = wVar3;
        this.liveSearch = wVar3;
        androidx.lifecycle.w wVar4 = new androidx.lifecycle.w();
        this.bannerLiveData = wVar4;
        this.liveBanner = wVar4;
        androidx.lifecycle.w wVar5 = new androidx.lifecycle.w();
        this.collectionLiveData = wVar5;
        this.liveCollection = wVar5;
        androidx.lifecycle.w wVar6 = new androidx.lifecycle.w();
        this.firstCollectionLiveData = wVar6;
        this.liveFirstCollection = wVar6;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void dispatchLiveChannelResult(int i10, int i11, List<LiveChannelEntity> list, k kVar) {
        if (this.liveChannelRequestVersion.get() != i10) {
            return;
        }
        if (list == null) {
            list = new ArrayList<>();
        }
        androidx.media3.common.p pVar = (androidx.media3.common.p) kVar;
        ((LiveViewModel) pVar.f2787c).lambda$getLiveChannel$0(pVar.f2786b, new j(list, i10));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$requestLiveChannel$0(xyz.stream.api.live.g gVar, int i10, int i11, k kVar) {
        dispatchLiveChannelResult(i10, i11, gVar.j(gVar.l()), kVar);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$requestLiveChannel$1(xyz.stream.api.live.g gVar, int i10, int i11, k kVar) {
        dispatchLiveChannelResult(i10, i11, gVar.j(gVar.n()), kVar);
    }

    public void getCategory() {
        int iIncrementAndGet = this.categoryRequestVersion.incrementAndGet();
        re.a aVarO = xyz.stream.api.live.g.o();
        if (aVarO == null) {
            u.a.f(this.categoryLiveData);
        } else {
            aVarO.e(new f(this, iIncrementAndGet));
        }
    }

    public void getCollectionChannels(int i10, int i11) {
        xyz.stream.api.o oVarF = xyz.stream.api.o.f();
        i iVar = new i(this, 1);
        oVarF.getClass();
        HashMap map = new HashMap();
        map.put("page_size", String.valueOf(i11));
        map.put("page", String.valueOf(i10));
        xyz.stream.api.o.g("live-collection/list", oVarF.n(), map, new xyz.stream.api.j(oVarF, iVar, "live-collection/list", map, 4));
    }

    public void getFirstCollectionChannels(TagLiveEntity tagLiveEntity) {
        xyz.stream.api.o oVarF = xyz.stream.api.o.f();
        String id2 = tagLiveEntity.getId();
        b bVar = new b(this, tagLiveEntity, 1);
        oVarF.getClass();
        HashMap mapO = u1.o(CmcdConfiguration.KEY_CONTENT_ID, id2);
        mapO.put("page", String.valueOf(1));
        mapO.put("page_size", String.valueOf(200));
        xyz.stream.api.o.g("live-collection/channel/list", oVarF.n(), mapO, new xyz.stream.api.j(oVarF, "live-collection/channel/list", mapO, bVar, 23));
    }

    public void getLiveCollectionBanner() {
        xyz.stream.api.o oVarF = xyz.stream.api.o.f();
        i iVar = new i(this, 0);
        oVarF.getClass();
        HashMap map = new HashMap();
        xyz.stream.api.o.g("live-collection/banner", oVarF.n(), map, new xyz.stream.api.j(oVarF, "live-collection/banner", map, iVar, 22));
    }

    public void getPropertiesChannels() {
        int iIncrementAndGet = this.propertiesRequestVersion.incrementAndGet();
        xyz.stream.api.o oVarF = xyz.stream.api.o.f();
        e eVar = new e(this, iIncrementAndGet);
        oVarF.getClass();
        HashMap map = new HashMap();
        xyz.stream.api.o.g("live/channels/properties", oVarF.n(), map, new xyz.stream.api.j(oVarF, eVar, "live/channels/properties", map, 3));
    }

    @Override // androidx.lifecycle.s0
    public void onCleared() {
        this.executor.shutdownNow();
        super.onCleared();
    }

    public int requestLiveChannel(final int i10, final k kVar) {
        final int iIncrementAndGet = this.liveChannelRequestVersion.incrementAndGet();
        final re.a aVarO = xyz.stream.api.live.g.o();
        if (aVarO == null) {
            dispatchLiveChannelResult(iIncrementAndGet, i10, new ArrayList(), kVar);
            return iIncrementAndGet;
        }
        if (i10 == -1) {
            final int i11 = 0;
            this.executor.execute(new Runnable(this) { // from class: xyz.stream.api.viewmodel.d

                /* JADX INFO: renamed from: b, reason: collision with root package name */
                public final /* synthetic */ BaseLiveViewModel f35964b;

                {
                    this.f35964b = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    int i12 = i11;
                    int i13 = iIncrementAndGet;
                    xyz.stream.api.live.g gVar = aVarO;
                    BaseLiveViewModel baseLiveViewModel = this.f35964b;
                    k kVar2 = kVar;
                    int i14 = i10;
                    switch (i12) {
                        case 0:
                            baseLiveViewModel.lambda$requestLiveChannel$0(gVar, i13, i14, kVar2);
                            break;
                        default:
                            baseLiveViewModel.lambda$requestLiveChannel$1(gVar, i13, i14, kVar2);
                            break;
                    }
                }
            });
            return iIncrementAndGet;
        }
        if (i10 == -2) {
            final int i12 = 1;
            this.executor.execute(new Runnable(this) { // from class: xyz.stream.api.viewmodel.d

                /* JADX INFO: renamed from: b, reason: collision with root package name */
                public final /* synthetic */ BaseLiveViewModel f35964b;

                {
                    this.f35964b = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    int i122 = i12;
                    int i13 = iIncrementAndGet;
                    xyz.stream.api.live.g gVar = aVarO;
                    BaseLiveViewModel baseLiveViewModel = this.f35964b;
                    k kVar2 = kVar;
                    int i14 = i10;
                    switch (i122) {
                        case 0:
                            baseLiveViewModel.lambda$requestLiveChannel$0(gVar, i13, i14, kVar2);
                            break;
                        default:
                            baseLiveViewModel.lambda$requestLiveChannel$1(gVar, i13, i14, kVar2);
                            break;
                    }
                }
            });
            return iIncrementAndGet;
        }
        aVarO.f35899b.execute(new androidx.activity.n(aVarO, new g(this, iIncrementAndGet, i10, kVar), i10, 21));
        return iIncrementAndGet;
    }

    public void searchLiveChannel(String str) {
        int iIncrementAndGet = this.searchRequestVersion.incrementAndGet();
        re.a aVarO = xyz.stream.api.live.g.o();
        if (aVarO == null) {
            u.a.f(this.searchLiveData);
        } else {
            aVarO.f35899b.execute(new androidx.emoji2.text.v(aVarO, new h(this, iIncrementAndGet), str, 23));
        }
    }
}
