package p000.p001.p002.p008.p009;

import androidx.lifecycle.LiveData;
import ar.tvplayer.core.data.db.dao.ؠ;
import ar.tvplayer.core.data.db.dao.ށ;
import ar.tvplayer.core.data.db.dao.ނ;
import ar.tvplayer.core.data.db.dao.ރ;
import ar.tvplayer.core.data.db.dao.ތ;
import ar.tvplayer.core.data.db.entities.ކ;
import ar.tvplayer.core.data.db.ހ;
import ar.tvplayer.core.domain.ލ;
import ar.tvplayer.core.domain.ޏ;
import ar.tvplayer.core.domain.ޑ;
import ar.tvplayer.core.util.CommonUtilsKt;
import java.util.Collection;
import java.util.List;
import p000.p001.p021.C1255;
import p000.p001.p021.p023.C1267;
import p000.p001.p021.p023.EnumC1270;
import p025.p026.InterfaceC1327;
import p037.p109.C2409;
import p037.p109.p111.C2423;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.C6549;
import p402.p405.InterfaceC6575;
import p402.p405.p406.EnumC6586;
import p402.p405.p407.p408.AbstractC6597;
import p402.p405.p407.p408.InterfaceC6593;
import p402.p411.p412.InterfaceC6618;
import p402.p411.p413.C6635;

/* JADX INFO: renamed from: ނ.֏.֏.ހ.֏.ލ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6593(c = "ar.tvplayer.tv.base.ui.ChannelsListViewModel$loadChannels$1", f = "ChannelsListViewModel.kt", l = {}, m = "invokeSuspend")
public final class C0811 extends AbstractC6597 implements InterfaceC6618<InterfaceC1327, InterfaceC6575<? super C6549>, Object> {

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public InterfaceC1327 f3367;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final /* synthetic */ C0804 f3368;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public final /* synthetic */ boolean f3369;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public final /* synthetic */ Collection f3370;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C0811(C0804 c0804, boolean z, Collection collection, InterfaceC6575 interfaceC6575) {
        super(2, interfaceC6575);
        this.f3368 = c0804;
        this.f3369 = z;
        this.f3370 = collection;
    }

    @Override // p402.p405.p407.p408.AbstractC6589
    /* JADX INFO: renamed from: ֏ */
    public final InterfaceC6575<C6549> mo837(Object obj, InterfaceC6575<?> interfaceC6575) {
        if (interfaceC6575 == null) {
            C6635.m9824("completion");
            throw null;
        }
        C0811 c0811 = new C0811(this.f3368, this.f3369, this.f3370, interfaceC6575);
        c0811.f3367 = (InterfaceC1327) obj;
        return c0811;
    }

    @Override // p402.p411.p412.InterfaceC6618
    /* JADX INFO: renamed from: ؠ */
    public final Object mo838(InterfaceC1327 interfaceC1327, InterfaceC6575<? super C6549> interfaceC6575) {
        return ((C0811) mo837(interfaceC1327, interfaceC6575)).mo839(C6549.f19328);
    }

    /* JADX WARN: Removed duplicated region for block: B:105:0x02ae  */
    /* JADX WARN: Removed duplicated region for block: B:109:0x02b5  */
    /* JADX WARN: Removed duplicated region for block: B:124:0x0370  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x0072  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0079  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00ce  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0133  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x013a  */
    /* JADX WARN: Removed duplicated region for block: B:81:0x025f  */
    @Override // p402.p405.p407.p408.AbstractC6589
    /* JADX INFO: renamed from: ށ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object mo839(Object obj) {
        int i;
        ؠ r3;
        LiveData liveDataM4455;
        int i2;
        ؠ r5;
        int i3;
        ؠ r32;
        EnumC6586 enumC6586 = EnumC6586.COROUTINE_SUSPENDED;
        C4303.m7198(obj);
        C0804 c0804 = this.f3368;
        boolean z = this.f3369;
        Collection<Long> collection = this.f3370;
        C1267 c1267 = c0804.f3347;
        if (c1267 == null) {
            C6635.m9822();
            throw null;
        }
        if (collection == null) {
            C6635.m9824("channelIdsToInclude");
            throw null;
        }
        EnumC1270 enumC1270M2558 = c1267.m2558();
        int iOrdinal = enumC1270M2558.ordinal();
        if (iOrdinal == 1) {
            ؠ r33 = ހ.֏().އ();
            long j = c1267.f4385;
            if (!(ޏ.ވ.ހ().length() > 0)) {
                if (CommonUtilsKt.ރ()) {
                    ޏ r6 = ޏ.ވ;
                    if (r6 == null) {
                        throw null;
                    }
                    boolean z2 = ((Number) ޏ.ބ.m9835(r6, ޏ.ށ[2])).intValue() == 2;
                    boolean z3 = ޑ.֏;
                    boolean z4 = C1255.f4369;
                    boolean z5 = ލ.ؠ;
                    if (z2 && z3 && (!z4 || z5)) {
                        i = 1;
                    }
                    r3 = r33;
                    if (r3 != null) {
                        throw null;
                    }
                    C2409 c2409M4490 = C2409.m4490("\n        SELECT c.id, c.playlist_id, p.name playlist_name, p.position playlist_position, p.tvg_shift playlist_tvg_shift,\n        p.catchup_type playlist_catchup_type, p.catchup_days playlist_catchup_days,\n        p.user_catchup_type playlist_user_catchup_type, p.user_catchup_days playlist_user_catchup_days, c.name,\n        c.custom_name, c.logo, t.icon_url logo_from_tvg, c.tvg_shift, b.tvg_channel_id tvg_channel_id,\n        s.time_offset tvg_source_time_offset, c.user_tvg_time_offset, c.catchup_days, c.position_in_playlist,\n        m.position manual_position, c.is_visible, c.is_blocked, o.is_blocked is_group_blocked, c.is_favorite,\n        c.watch_time, p.logos_priority, c.use_external_player\n        FROM channels c\n        INNER JOIN playlists p ON c.playlist_id == p.id\n        LEFT OUTER JOIN channel_tvg_bindings b ON c.id == b.channel_id\n        LEFT OUTER JOIN tvg_channels t ON b.tvg_channel_id == t.id\n        LEFT OUTER JOIN tvg_sources s ON t.tvg_source_id == s.id\n        LEFT OUTER JOIN channel_manual_positions m ON c.id == m.channel_id\n            AND m.type == 2\n            AND m.playlist_id == ?\n        LEFT OUTER JOIN channel_group_options o ON o.playlist_id == c.playlist_id\n            AND o.type == 4\n            AND o.group_name == c.`group`\n        LEFT OUTER JOIN channel_group_options o2 ON o2.playlist_id == ?\n            AND o2.type == 2\n        WHERE p.is_enabled == 1\n            AND c.is_vod == 0\n            AND (c.is_visible == 1 OR ? == 1 OR ? == 0)\n            AND CASE WHEN ? == 0\n                THEN p.is_visible_in_all_channels == 1\n                ELSE p.id == ?\n                END\n            AND (o.is_visible IS NULL OR o.is_visible == 1\n                OR (o2.show_channels_from_hidden_groups IS NOT NULL AND o2.show_channels_from_hidden_groups == 1)\n                OR ? == 0)\n        ", 7);
                    c2409M4490.bindLong(1, j);
                    c2409M4490.bindLong(2, j);
                    c2409M4490.bindLong(3, z ? 1L : 0L);
                    long j2 = i;
                    c2409M4490.bindLong(4, j2);
                    c2409M4490.bindLong(5, j);
                    c2409M4490.bindLong(6, j);
                    c2409M4490.bindLong(7, j2);
                    liveDataM4455 = r3.֏.f7599.m4455(new String[]{"channels", "playlists", "channel_tvg_bindings", "tvg_channels", "tvg_sources", "channel_manual_positions", "channel_group_options"}, false, new ށ(r3, c2409M4490));
                }
                i = 0;
                r3 = r33;
                if (r3 != null) {
                }
            }
        } else if (iOrdinal == 2) {
            ؠ r52 = ހ.֏().އ();
            long j3 = c1267.f4385;
            if (!(ޏ.ވ.ހ().length() > 0)) {
                if (CommonUtilsKt.ރ()) {
                    ޏ r4 = ޏ.ވ;
                    if (r4 == null) {
                        throw null;
                    }
                    boolean z6 = ((Number) ޏ.ބ.m9835(r4, ޏ.ށ[2])).intValue() == 2;
                    boolean z7 = ޑ.֏;
                    boolean z8 = C1255.f4369;
                    boolean z9 = ލ.ؠ;
                    if (z6 && z7 && (!z8 || z9)) {
                        i2 = 1;
                    }
                    r5 = r52;
                    if (r5 != null) {
                        throw null;
                    }
                    StringBuilder sb = new StringBuilder();
                    sb.append("\n");
                    sb.append("        SELECT c.id, c.playlist_id, p.name playlist_name, p.position playlist_position, p.tvg_shift playlist_tvg_shift,");
                    sb.append("\n");
                    sb.append("        p.catchup_type playlist_catchup_type, p.catchup_days playlist_catchup_days,");
                    sb.append("\n");
                    C2803.m4893(sb, "        p.user_catchup_type playlist_user_catchup_type, p.user_catchup_days playlist_user_catchup_days, c.name,", "\n", "        c.custom_name, c.logo, t.icon_url logo_from_tvg, c.tvg_shift, b.tvg_channel_id tvg_channel_id,", "\n");
                    C2803.m4893(sb, "        s.time_offset tvg_source_time_offset, c.user_tvg_time_offset, c.catchup_days, c.position_in_playlist,", "\n", "        m.position manual_position, c.is_visible, c.is_blocked, o.is_blocked is_group_blocked, c.is_favorite,", "\n");
                    C2803.m4893(sb, "        c.watch_time, p.logos_priority, c.use_external_player", "\n", "        FROM channels c", "\n");
                    C2803.m4893(sb, "        INNER JOIN playlists p ON c.playlist_id == p.id", "\n", "        LEFT OUTER JOIN channel_tvg_bindings b ON c.id == b.channel_id", "\n");
                    C2803.m4893(sb, "        LEFT OUTER JOIN tvg_channels t ON b.tvg_channel_id == t.id", "\n", "        LEFT OUTER JOIN tvg_sources s ON t.tvg_source_id == s.id", "\n");
                    C2803.m4893(sb, "        LEFT OUTER JOIN channel_manual_positions m ON c.id == m.channel_id", "\n", "            AND m.type == 3", "\n");
                    C2803.m4893(sb, "            AND m.playlist_id == ", "?", "\n", "        LEFT OUTER JOIN channel_group_options o ON o.playlist_id == c.playlist_id");
                    C2803.m4893(sb, "\n", "            AND o.type == 4", "\n", "            AND o.group_name == c.`group`");
                    C2803.m4893(sb, "\n", "        LEFT OUTER JOIN channel_group_options o2 ON o2.playlist_id == ", "?", "\n");
                    C2803.m4893(sb, "            AND o2.type == 3", "\n", "        WHERE p.is_enabled == 1", "\n");
                    C2803.m4893(sb, "            AND (c.is_visible == 1 OR ", "?", " == 1 OR ", "?");
                    sb.append(" == 0)");
                    sb.append("\n");
                    sb.append("            AND ((c.is_favorite == 1 OR c.id IN (");
                    int size = collection.size();
                    C2423.m4508(sb, size);
                    sb.append(")) AND ");
                    sb.append("?");
                    sb.append(" == 1)");
                    sb.append("\n");
                    sb.append("            AND CASE WHEN ");
                    C2803.m4893(sb, "?", " == 0", "\n", "                THEN p.is_visible_in_all_favorites == 1");
                    C2803.m4893(sb, "\n", "                ELSE p.id == ", "?", "\n");
                    C2803.m4893(sb, "                END", "\n", "            AND (o.is_visible IS NULL OR o.is_visible == 1", "\n");
                    C2803.m4893(sb, "                OR (o2.show_channels_from_hidden_groups IS NOT NULL AND o2.show_channels_from_hidden_groups == 1)", "\n", "                OR ", "?");
                    sb.append(" == 0)");
                    sb.append("\n");
                    sb.append("        ");
                    String string = sb.toString();
                    int i4 = size + 8;
                    C2409 c2409M44902 = C2409.m4490(string, i4);
                    c2409M44902.bindLong(1, j3);
                    c2409M44902.bindLong(2, j3);
                    c2409M44902.bindLong(3, z ? 1L : 0L);
                    long j4 = i2;
                    c2409M44902.bindLong(4, j4);
                    int i5 = 5;
                    for (Long l : collection) {
                        if (l == null) {
                            c2409M44902.bindNull(i5);
                        } else {
                            c2409M44902.bindLong(i5, l.longValue());
                        }
                        i5++;
                    }
                    c2409M44902.bindLong(size + 5, j4);
                    c2409M44902.bindLong(size + 6, j3);
                    c2409M44902.bindLong(size + 7, j3);
                    c2409M44902.bindLong(i4, j4);
                    liveDataM4455 = r5.֏.f7599.m4455(new String[]{"channels", "playlists", "channel_tvg_bindings", "tvg_channels", "tvg_sources", "channel_manual_positions", "channel_group_options"}, false, new ނ(r5, c2409M44902));
                }
                i2 = 0;
                r5 = r52;
                if (r5 != null) {
                }
            }
        } else {
            if (iOrdinal != 3) {
                throw new IllegalStateException("Unhandled group type: " + enumC1270M2558);
            }
            ؠ r34 = ހ.֏().އ();
            long j5 = c1267.f4385;
            String str = c1267.f4386;
            if (!(ޏ.ވ.ހ().length() > 0)) {
                if (CommonUtilsKt.ރ()) {
                    ޏ r12 = ޏ.ވ;
                    if (r12 == null) {
                        throw null;
                    }
                    boolean z10 = ((Number) ޏ.ބ.m9835(r12, ޏ.ށ[2])).intValue() == 2;
                    boolean z11 = ޑ.֏;
                    boolean z12 = C1255.f4369;
                    boolean z13 = ލ.ؠ;
                    if (z10 && z11 && (!z12 || z13)) {
                        i3 = 1;
                    }
                    r32 = r34;
                    if (r32 != null) {
                        throw null;
                    }
                    C2409 c2409M44903 = C2409.m4490("\n        SELECT c.id, c.playlist_id, p.name playlist_name, p.position playlist_position, p.tvg_shift playlist_tvg_shift,\n        p.catchup_type playlist_catchup_type, p.catchup_days playlist_catchup_days,\n        p.user_catchup_type playlist_user_catchup_type, p.user_catchup_days playlist_user_catchup_days, c.name,\n        c.custom_name, c.logo, t.icon_url logo_from_tvg, c.tvg_shift, b.tvg_channel_id tvg_channel_id,\n        s.time_offset tvg_source_time_offset, c.user_tvg_time_offset, c.catchup_days, c.position_in_playlist,\n        m.position manual_position, c.is_visible, c.is_blocked, o.is_blocked is_group_blocked, c.is_favorite,\n        c.watch_time, p.logos_priority, c.use_external_player\n        FROM channels c\n        INNER JOIN playlists p ON c.playlist_id == p.id\n        LEFT OUTER JOIN channel_tvg_bindings b ON c.id == b.channel_id\n        LEFT OUTER JOIN tvg_channels t ON b.tvg_channel_id == t.id\n        LEFT OUTER JOIN tvg_sources s ON t.tvg_source_id == s.id\n        LEFT OUTER JOIN channel_manual_positions m ON c.id == m.channel_id\n            AND m.type == 4\n            AND m.playlist_id == ?\n            AND m.group_name == ?\n        LEFT OUTER JOIN channel_group_options o ON o.playlist_id == c.playlist_id\n            AND o.type == 4\n            AND o.group_name == c.`group`\n        WHERE p.is_enabled == 1\n            AND (c.is_visible == 1 OR ? == 1 OR ? == 0)\n            AND p.id == ?\n            AND c.`group` == ?\n            AND (o.is_visible IS NULL OR o.is_visible == 1 OR ? == 0)\n            AND (o.are_favorites_only IS NULL OR o.are_favorites_only == 0 OR c.is_favorite == 1 OR ? == 0)\n        ", 8);
                    c2409M44903.bindLong(1, j5);
                    if (str == null) {
                        c2409M44903.bindNull(2);
                    } else {
                        c2409M44903.bindString(2, str);
                    }
                    c2409M44903.bindLong(3, z ? 1L : 0L);
                    long j6 = i3;
                    c2409M44903.bindLong(4, j6);
                    c2409M44903.bindLong(5, j5);
                    if (str == null) {
                        c2409M44903.bindNull(6);
                    } else {
                        c2409M44903.bindString(6, str);
                    }
                    c2409M44903.bindLong(7, j6);
                    c2409M44903.bindLong(8, j6);
                    liveDataM4455 = r32.֏.f7599.m4455(new String[]{"channels", "playlists", "channel_tvg_bindings", "tvg_channels", "tvg_sources", "channel_manual_positions", "channel_group_options"}, false, new ރ(r32, c2409M44903));
                }
                i3 = 0;
                r32 = r34;
                if (r32 != null) {
                }
            }
        }
        LiveData<List<ar.tvplayer.core.data.db.entities.ނ>> liveData = CommonUtilsKt.֏(liveDataM4455);
        c0804.f3340 = liveData;
        c0804.f3339.m4290(liveData, new C0812(c0804));
        C0804 c08042 = this.f3368;
        C1267 c12672 = c08042.f3347;
        if (c12672 == null) {
            C6635.m9822();
            throw null;
        }
        ތ r35 = ހ.֏().ވ();
        EnumC1270 enumC1270M25582 = c12672.m2558();
        long j7 = c12672.f4385;
        String str2 = c12672.f4386;
        ތ r36 = r35;
        if (r36 == null) {
            throw null;
        }
        C2409 c2409M44904 = C2409.m4490("\n        SELECT * FROM channel_group_options\n        WHERE type == ? AND playlist_id == ? AND group_name == ?\n        ", 3);
        c2409M44904.bindLong(1, r36.ހ.֏(enumC1270M25582));
        c2409M44904.bindLong(2, j7);
        if (str2 == null) {
            c2409M44904.bindNull(3);
        } else {
            c2409M44904.bindString(3, str2);
        }
        LiveData<ކ> liveData2 = CommonUtilsKt.֏(r36.֏.f7599.m4455(new String[]{"channel_group_options"}, false, new ar.tvplayer.core.data.db.dao.ލ(r36, c2409M44904)));
        c08042.f3341 = liveData2;
        c08042.f3339.m4290(liveData2, new C0810(c08042));
        return C6549.f19328;
    }
}
