package xyz.stream.api.database;

import androidx.room.RoomDatabase;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import tv.danmaku.ijk.media.player.IjkMediaMeta;
import vf.x;
import xyz.stream.api.database.entity.LiveFavorite;
import xyz.stream.api.database.entity.LiveHistory;
import xyz.stream.api.database.entity.RecordEntity;
import xyz.stream.api.entity.BaseEntity;
import xyz.stream.utils.f0;

/* JADX INFO: loaded from: classes3.dex */
public final class k implements xyz.stream.api.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f35824a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ Object f35826c;

    public /* synthetic */ k(Object obj, Object obj2, int i10) {
        this.f35824a = i10;
        this.f35826c = obj;
        this.f35825b = obj2;
    }

    @Override // xyz.stream.api.e
    public final void a(String str) {
        int i10 = this.f35824a;
        Object obj = this.f35825b;
        switch (i10) {
            case 0:
                List list = (List) obj;
                if (list != null && !list.isEmpty()) {
                    Iterator it = list.iterator();
                    while (it.hasNext()) {
                        xyz.stream.api.o.f().y(((LiveHistory) it.next()).getChannelId().intValue());
                    }
                    break;
                }
                break;
            case 1:
                break;
            default:
                List listB = ((vf.i) ((q) this.f35826c).f35844b).b(f0.o().q("flutter.selectRoles", ""));
                o oVar = (o) obj;
                if (oVar != null) {
                    oVar.d(listB);
                }
                break;
        }
    }

    public final void b(BaseEntity baseEntity) {
        LiveHistory liveHistory;
        LiveFavorite liveFavorite;
        RecordEntity recordEntity;
        q qVar;
        ArrayList arrayList;
        Object obj;
        Integer numValueOf;
        Object obj2;
        Object obj3;
        List list;
        int i10;
        Integer numValueOf2;
        Iterator it;
        Object obj4;
        Integer numValueOf3;
        int i11 = this.f35824a;
        Object obj5 = this.f35825b;
        String str = "";
        String str2 = "flutter.selectRoles";
        Object obj6 = this.f35826c;
        switch (i11) {
            case 0:
                if (baseEntity == null || baseEntity.getData() == null) {
                    List list2 = (List) obj5;
                    if (list2 != null && !list2.isEmpty()) {
                        Iterator it2 = list2.iterator();
                        while (it2.hasNext()) {
                            xyz.stream.api.o.f().x(((LiveHistory) it2.next()).getChannelId().intValue());
                        }
                        break;
                    }
                } else {
                    List<Map> list3 = (List) xyz.stream.utils.m.f36162a.fromJson(baseEntity.getData(), new LiveRecordManager$1$1().getType());
                    if (list3 != null && !list3.isEmpty()) {
                        ArrayList arrayList2 = new ArrayList();
                        for (Map map : list3) {
                            Integer numValueOf4 = Integer.valueOf(Double.valueOf(String.valueOf(map.get("channel_id"))).intValue());
                            String str3 = (String) map.get("updated_at");
                            LiveHistory liveHistory2 = new LiveHistory();
                            liveHistory2.setChannelId(numValueOf4);
                            liveHistory2.setUpdateDate(kotlinx.coroutines.flow.h.i(str3, "yyyy-MM-dd HH:mm:ss.SSS"));
                            liveHistory2.setRoleId(f0.o().q("flutter.selectRoles", ""));
                            arrayList2.add(liveHistory2);
                            Iterator it3 = ((List) obj5).iterator();
                            while (true) {
                                if (it3.hasNext()) {
                                    liveHistory = (LiveHistory) it3.next();
                                    if (liveHistory.getChannelId().equals(numValueOf4)) {
                                    }
                                } else {
                                    liveHistory = null;
                                }
                            }
                            if (liveHistory == null) {
                                com.bumptech.glide.load.engine.p pVar = (com.bumptech.glide.load.engine.p) ((l) obj6).f35829b;
                                androidx.room.util.b.b((RoomDatabase) pVar.f5756a, false, true, new vf.n(pVar, liveHistory2, 1));
                            } else {
                                liveHistory2.setId(liveHistory.getId());
                                com.bumptech.glide.load.engine.p pVar2 = (com.bumptech.glide.load.engine.p) ((l) obj6).f35829b;
                                androidx.room.util.b.b((RoomDatabase) pVar2.f5756a, false, true, new vf.n(pVar2, liveHistory2, 0));
                            }
                        }
                        for (LiveHistory liveHistory3 : (List) obj5) {
                            Iterator it4 = arrayList2.iterator();
                            while (true) {
                                if (it4.hasNext()) {
                                    if (((LiveHistory) it4.next()).getChannelId().equals(liveHistory3.getChannelId())) {
                                    }
                                } else {
                                    com.bumptech.glide.load.engine.p pVar3 = (com.bumptech.glide.load.engine.p) ((l) obj6).f35829b;
                                    androidx.room.util.b.b((RoomDatabase) pVar3.f5756a, false, true, new vf.n(pVar3, liveHistory3, 2));
                                }
                                break;
                            }
                        }
                        break;
                    } else {
                        List list4 = (List) obj5;
                        if (list4 != null && !list4.isEmpty()) {
                            Iterator it5 = list4.iterator();
                            while (it5.hasNext()) {
                                xyz.stream.api.o.f().x(((LiveHistory) it5.next()).getChannelId().intValue());
                            }
                            break;
                        }
                    }
                }
                break;
            case 1:
                if (baseEntity == null || baseEntity.getData() == null) {
                    List list5 = (List) obj5;
                    if (list5 != null && !list5.isEmpty()) {
                        Iterator it6 = list5.iterator();
                        while (it6.hasNext()) {
                            xyz.stream.api.o.f().w(((LiveFavorite) it6.next()).getChannelId().intValue());
                        }
                        break;
                    }
                } else {
                    List<Map> list6 = (List) xyz.stream.utils.m.f36162a.fromJson(baseEntity.getData(), new LiveRecordManager$2$1().getType());
                    if (list6 != null && !list6.isEmpty()) {
                        ArrayList arrayList3 = new ArrayList();
                        for (Map map2 : list6) {
                            Integer numValueOf5 = Integer.valueOf(Double.valueOf(String.valueOf(map2.get("channel_id"))).intValue());
                            String str4 = (String) map2.get("updated_at");
                            LiveFavorite liveFavorite2 = new LiveFavorite();
                            liveFavorite2.setChannelId(numValueOf5);
                            liveFavorite2.setUpdateDate(kotlinx.coroutines.flow.h.i(str4, "yyyy-MM-dd HH:mm:ss.SSS"));
                            liveFavorite2.setRoleId(f0.o().q("flutter.selectRoles", ""));
                            arrayList3.add(liveFavorite2);
                            Iterator it7 = ((List) obj5).iterator();
                            while (true) {
                                if (it7.hasNext()) {
                                    liveFavorite = (LiveFavorite) it7.next();
                                    if (liveFavorite.getChannelId().equals(numValueOf5)) {
                                    }
                                } else {
                                    liveFavorite = null;
                                }
                            }
                            if (liveFavorite == null) {
                                com.bumptech.glide.load.engine.p pVar4 = (com.bumptech.glide.load.engine.p) ((l) obj6).f35829b;
                                androidx.room.util.b.b((RoomDatabase) pVar4.f5756a, false, true, new vf.o(pVar4, liveFavorite2, 0));
                            } else {
                                liveFavorite2.setId(liveFavorite.getId());
                                com.bumptech.glide.load.engine.p pVar5 = (com.bumptech.glide.load.engine.p) ((l) obj6).f35829b;
                                androidx.room.util.b.b((RoomDatabase) pVar5.f5756a, false, true, new vf.o(pVar5, liveFavorite2, 1));
                            }
                        }
                        for (LiveFavorite liveFavorite3 : (List) obj5) {
                            Iterator it8 = arrayList3.iterator();
                            while (true) {
                                if (it8.hasNext()) {
                                    if (((LiveFavorite) it8.next()).getChannelId().equals(liveFavorite3.getChannelId())) {
                                    }
                                } else {
                                    com.bumptech.glide.load.engine.p pVar6 = (com.bumptech.glide.load.engine.p) ((l) obj6).f35829b;
                                    androidx.room.util.b.b((RoomDatabase) pVar6.f5756a, false, true, new vf.o(pVar6, liveFavorite3, 2));
                                }
                                break;
                            }
                        }
                        break;
                    } else {
                        List list7 = (List) obj5;
                        if (list7 != null && !list7.isEmpty()) {
                            Iterator it9 = list7.iterator();
                            while (it9.hasNext()) {
                                xyz.stream.api.o.f().w(((LiveFavorite) it9.next()).getChannelId().intValue());
                            }
                            break;
                        }
                    }
                }
                break;
            default:
                q qVar2 = (q) obj6;
                List listB = ((vf.i) qVar2.f35844b).b(f0.o().q("flutter.selectRoles", ""));
                if (baseEntity == null || baseEntity.getData() == null) {
                    o oVar = (o) obj5;
                    if (oVar != null) {
                        oVar.d(listB);
                    }
                } else {
                    JsonElement data = baseEntity.getData();
                    JsonElement jsonElement = (data == null || !data.isJsonObject()) ? null : data.getAsJsonObject().get("list");
                    if (jsonElement == null || jsonElement.isJsonNull()) {
                        Iterator it10 = listB.iterator();
                        while (it10.hasNext()) {
                            ((vf.i) qVar2.f35844b).a((RecordEntity) it10.next());
                        }
                        listB.clear();
                        o oVar2 = (o) obj5;
                        if (oVar2 != null) {
                            oVar2.d(listB);
                        }
                    } else {
                        List list8 = (List) xyz.stream.utils.m.f36162a.fromJson(jsonElement, new RecordManager$1$1().getType());
                        if (list8 == null || list8.isEmpty()) {
                            Iterator it11 = listB.iterator();
                            while (it11.hasNext()) {
                                ((vf.i) qVar2.f35844b).a((RecordEntity) it11.next());
                            }
                            listB.clear();
                            o oVar3 = (o) obj5;
                            if (oVar3 != null) {
                                oVar3.d(listB);
                            }
                        } else {
                            ArrayList arrayList4 = new ArrayList();
                            Iterator it12 = list8.iterator();
                            while (it12.hasNext()) {
                                Map map3 = (Map) it12.next();
                                int iIntValue = map3.get("source_type") != null ? Double.valueOf(String.valueOf(map3.get("source_type"))).intValue() : 0;
                                Iterator it13 = it12;
                                Object obj7 = obj5;
                                String str5 = str;
                                String str6 = str2;
                                q qVar3 = qVar2;
                                List list9 = listB;
                                ArrayList arrayList5 = arrayList4;
                                Object obj8 = "hardware_decode";
                                if (iIntValue == 3) {
                                    if (map3.get("episodes") != null) {
                                        Object obj9 = map3.get("episodes");
                                        obj2 = "episode_number";
                                        Gson gson = xyz.stream.utils.m.f36162a;
                                        obj3 = "season_number";
                                        list = (List) gson.fromJson(gson.toJsonTree(obj9), new RecordManager$1$2().getType());
                                    } else {
                                        obj2 = "episode_number";
                                        obj3 = "season_number";
                                        list = null;
                                    }
                                    if (list != null && !list.isEmpty()) {
                                        Iterator it14 = list.iterator();
                                        while (it14.hasNext()) {
                                            Map map4 = (Map) it14.next();
                                            String strI = kotlinx.coroutines.flow.h.i((String) map4.get("updated_at"), "yyyy-MM-dd HH:mm:ss.SSS");
                                            String str7 = (String) map3.get(IjkMediaMeta.IJKM_KEY_TITLE);
                                            Integer numValueOf6 = Integer.valueOf(Double.valueOf(String.valueOf(map4.get("video_id"))).intValue());
                                            Integer numValueOf7 = map4.get("series_id") != null ? Integer.valueOf(Double.valueOf(String.valueOf(map4.get("series_id"))).intValue()) : null;
                                            Integer numValueOf8 = map4.get("play_time") != null ? Integer.valueOf(Double.valueOf(String.valueOf(map4.get("play_time"))).intValue()) : null;
                                            Integer numValueOf9 = map4.get("total_time") != null ? Integer.valueOf(Double.valueOf(String.valueOf(map4.get("total_time"))).intValue()) : null;
                                            String str8 = (String) map4.get("video_pic");
                                            String str9 = (String) map3.get("role_id");
                                            Integer numValueOf10 = Integer.valueOf(iIntValue);
                                            String str10 = (String) map4.get("imdb_id");
                                            Double dValueOf = Double.valueOf(map4.get("subtitle_delay") != null ? Double.parseDouble(String.valueOf(map4.get("subtitle_delay"))) : 0.0d);
                                            Object obj10 = obj3;
                                            if (map4.get(obj10) != null) {
                                                i10 = iIntValue;
                                                numValueOf2 = Integer.valueOf(Double.valueOf(String.valueOf(map4.get(obj10))).intValue());
                                            } else {
                                                i10 = iIntValue;
                                                numValueOf2 = null;
                                            }
                                            Object obj11 = obj2;
                                            if (map4.get(obj11) != null) {
                                                it = it14;
                                                numValueOf3 = Integer.valueOf(Double.valueOf(String.valueOf(map4.get(obj11))).intValue());
                                                obj4 = obj8;
                                            } else {
                                                it = it14;
                                                obj4 = obj8;
                                                numValueOf3 = null;
                                            }
                                            obj8 = obj4;
                                            arrayList5.add(RecordEntity.make(str7, numValueOf6, numValueOf7, numValueOf8, strI, numValueOf9, str8, str9, numValueOf10, str10, dValueOf, numValueOf2, numValueOf3, Integer.valueOf(map4.get(obj4) != null ? Double.valueOf(String.valueOf(map4.get(obj4))).intValue() : 1), null, null));
                                            it14 = it;
                                            obj2 = obj11;
                                            iIntValue = i10;
                                            obj3 = obj10;
                                        }
                                    }
                                    arrayList = arrayList5;
                                } else {
                                    arrayList = arrayList5;
                                    String strI2 = kotlinx.coroutines.flow.h.i((String) map3.get("updated_at"), "yyyy-MM-dd HH:mm:ss.SSS");
                                    String str11 = (String) map3.get(IjkMediaMeta.IJKM_KEY_TITLE);
                                    Integer numValueOf11 = Integer.valueOf(Double.valueOf(String.valueOf(map3.get("video_id"))).intValue());
                                    Integer numValueOf12 = map3.get("series_id") != null ? Integer.valueOf(Double.valueOf(String.valueOf(map3.get("series_id"))).intValue()) : null;
                                    Integer numValueOf13 = map3.get("play_time") != null ? Integer.valueOf(Double.valueOf(String.valueOf(map3.get("play_time"))).intValue()) : null;
                                    Integer numValueOf14 = map3.get("total_time") != null ? Integer.valueOf(Double.valueOf(String.valueOf(map3.get("total_time"))).intValue()) : null;
                                    String str12 = (String) map3.get("video_pic");
                                    String str13 = (String) map3.get("role_id");
                                    Integer numValueOf15 = Integer.valueOf(map3.get("source_type") != null ? Double.valueOf(String.valueOf(map3.get("source_type"))).intValue() : 0);
                                    String str14 = (String) map3.get("imdb_id");
                                    Double dValueOf2 = Double.valueOf(map3.get("subtitle_delay") != null ? Double.parseDouble(String.valueOf(map3.get("subtitle_delay"))) : 0.0d);
                                    Integer numValueOf16 = map3.get("season_number") != null ? Integer.valueOf(Double.valueOf(String.valueOf(map3.get("season_number"))).intValue()) : null;
                                    if (map3.get("episode_number") != null) {
                                        numValueOf = Integer.valueOf(Double.valueOf(String.valueOf(map3.get("episode_number"))).intValue());
                                        obj = obj8;
                                    } else {
                                        obj = obj8;
                                        numValueOf = null;
                                    }
                                    arrayList.add(RecordEntity.make(str11, numValueOf11, numValueOf12, numValueOf13, strI2, numValueOf14, str12, str13, numValueOf15, str14, dValueOf2, numValueOf16, numValueOf, Integer.valueOf(map3.get(obj) != null ? Double.valueOf(String.valueOf(map3.get(obj))).intValue() : 1), null, null));
                                }
                                arrayList4 = arrayList;
                                it12 = it13;
                                obj5 = obj7;
                                str = str5;
                                str2 = str6;
                                qVar2 = qVar3;
                                listB = list9;
                            }
                            List<RecordEntity> list10 = listB;
                            Object obj12 = obj5;
                            String str15 = str;
                            String str16 = str2;
                            q qVar4 = qVar2;
                            ArrayList<RecordEntity> arrayList6 = arrayList4;
                            for (RecordEntity recordEntity2 : arrayList6) {
                                Iterator it15 = list10.iterator();
                                while (true) {
                                    if (it15.hasNext()) {
                                        recordEntity = (RecordEntity) it15.next();
                                        if (!recordEntity.getVideoId().equals(recordEntity2.getVideoId()) || !recordEntity.getRoleId().equals(recordEntity2.getRoleId()) || !recordEntity.getSourceType().equals(recordEntity2.getSourceType())) {
                                        }
                                    } else {
                                        recordEntity = null;
                                    }
                                }
                                if (recordEntity == null) {
                                    qVar = qVar4;
                                    vf.i iVar = (vf.i) qVar.f35844b;
                                    iVar.getClass();
                                    androidx.room.util.b.b(iVar.f33973a, false, true, new x(iVar, recordEntity2, 0));
                                } else {
                                    qVar = qVar4;
                                    recordEntity2.setId(recordEntity.getId());
                                    vf.i iVar2 = (vf.i) qVar.f35844b;
                                    iVar2.getClass();
                                    androidx.room.util.b.b(iVar2.f33973a, false, true, new x(iVar2, recordEntity2, 2));
                                }
                                qVar4 = qVar;
                            }
                            q qVar5 = qVar4;
                            for (RecordEntity recordEntity3 : list10) {
                                Iterator it16 = arrayList6.iterator();
                                while (true) {
                                    if (it16.hasNext()) {
                                        RecordEntity recordEntity4 = (RecordEntity) it16.next();
                                        if (recordEntity4.getSourceType().intValue() == 2) {
                                            if (!recordEntity3.getVideoId().equals(recordEntity4.getVideoId()) || !recordEntity3.getRoleId().equals(recordEntity4.getRoleId()) || !recordEntity3.getSourceType().equals(recordEntity4.getSourceType())) {
                                            }
                                        } else if (recordEntity4.getSourceType().intValue() != 3 || !recordEntity3.getSeriesId().equals(recordEntity4.getSeriesId()) || !recordEntity3.getRoleId().equals(recordEntity4.getRoleId()) || !recordEntity3.getSourceType().equals(recordEntity4.getSourceType())) {
                                        }
                                    } else {
                                        ((vf.i) qVar5.f35844b).a(recordEntity3);
                                    }
                                }
                            }
                            List listB2 = ((vf.i) qVar5.f35844b).b(f0.o().q(str16, str15));
                            o oVar4 = (o) obj12;
                            if (oVar4 != null) {
                                oVar4.d(listB2);
                            }
                        }
                    }
                }
                break;
        }
    }

    @Override // xyz.stream.api.e
    public final /* bridge */ /* synthetic */ void onSuccess(Object obj) {
        switch (this.f35824a) {
            case 0:
                b((BaseEntity) obj);
                break;
            case 1:
                b((BaseEntity) obj);
                break;
            default:
                b((BaseEntity) obj);
                break;
        }
    }
}
