package com.bytedance.ext_power_list;

import X.4h3;
import X.4r1;
import X.7AW;
import X.7he;
import X.A4l;
import X.A4m;
import X.A4n;
import X.A4o;
import X.A4p;
import X.C0295Crj;
import X.C1481DaP;
import X.C1486DaU;
import X.C1663DdL;
import X.C1676DdY;
import X.C1677DdZ;
import X.C1678Dda;
import X.C1680Ddc;
import X.C1681Ddd;
import X.C1682Dde;
import X.C1683Ddf;
import X.C1685Ddh;
import X.C1686Ddi;
import X.C1687Ddj;
import X.C1688Ddk;
import X.C1689Ddl;
import X.C1690Ddm;
import X.C1694Ddq;
import X.C1696Dds;
import X.C1697Ddt;
import X.C1698Ddu;
import X.DWK;
import X.DWM;
import X.M12;
import com.bytedance.covode.number.Covode;
import java.util.Collection;
import java.util.List;

public abstract class AssemListViewModel<S extends DWK<S, ITEM>, ITEM extends C1481DaP, Cursor> extends AssemSingleListViewModel<ITEM, S, Cursor> {
    public final C0295Crj config$delegate = 7he.LIZ(new C1697Ddt(this));
    public C1676DdY<ITEM> state;

    static {
        Covode.recordClassIndex(25768);
    }

    public Object onLoadLatest(Cursor cursor, 4r1<? super A4l<Cursor>> r3) {
        return A4n.LIZ(A4l.LIZ);
    }

    public abstract Object onLoadMore(Cursor cursor, 4r1<? super A4l<Cursor>> r2);

    public abstract Object onRefresh(4r1<? super A4l<Cursor>> r1);

    public final C1486DaU<Cursor> getConfig() {
        return (C1486DaU) this.config$delegate.getValue();
    }

    public void listClear() {
        withState(new C1689Ddl(this));
    }

    public void manualListRefresh() {
        getConfig().LIZLLL.LIZLLL();
    }

    public List<ITEM> listGetAll() {
        List<C1481DaP> LIZJ;
        C1676DdY<ITEM> ddY = this.state;
        if (ddY == null) {
            LIZJ = null;
        } else {
            LIZJ = ddY.LIZJ();
        }
        if (LIZJ instanceof List) {
            return LIZJ;
        }
        return null;
    }

    public final void setListState(C1676DdY<?> ddY) {
        M12.LIZ(ddY);
        this.state = ddY;
    }

    public void listAddAll(Collection<? extends ITEM> collection) {
        M12.LIZ(collection);
        withState(new C1685Ddh(this, collection));
    }

    public void listAddItem(ITEM item) {
        M12.LIZ(item);
        withState(new C1687Ddj(this, item));
    }

    public ITEM listGetAt(int i) {
        C1676DdY<ITEM> ddY = this.state;
        if (ddY == null) {
            return null;
        }
        return ddY.LIZIZ(i);
    }

    public int listIndexOf(ITEM item) {
        M12.LIZ(item);
        C1676DdY<ITEM> ddY = this.state;
        if (ddY == null) {
            return -1;
        }
        return ddY.LIZJ(item);
    }

    public void listRemoveItem(ITEM item) {
        M12.LIZ(item);
        withState(new C1688Ddk(this, item));
    }

    public void listRemoveItemAt(int i) {
        withState(new C1690Ddm(this, i));
    }

    public void listSetItem(ITEM item) {
        M12.LIZ(item);
        withState(new C1686Ddi(this, item));
    }

    public void listSetItems(Collection<? extends ITEM> collection) {
        M12.LIZ(collection);
        withState(new C1682Dde(this, collection));
    }

    public void manualListLoadLatest(Cursor cursor) {
        getConfig().LIZLLL.LIZ(cursor);
    }

    public void manualListLoadMore(Cursor cursor) {
        getConfig().LIZLLL.LIZIZ(cursor);
    }

    public void manualListRetry(C1663DdL ddL) {
        M12.LIZ(ddL);
        getConfig().LIZLLL.LIZ(ddL);
    }

    /* access modifiers changed from: private */
    public final A4l<Cursor> toValue(C1683Ddf<ITEM> ddf) {
        if (ddf instanceof C1694Ddq) {
            C1694Ddq ddq = (C1694Ddq) ddf;
            return A4l.LIZ.LIZ(ddq.LIZIZ, ddq.LIZJ, ddq.LIZLLL);
        } else if (ddf instanceof C1698Ddu) {
            return A4l.LIZ.LIZ(new Exception(((C1698Ddu) ddf).LIZIZ));
        } else {
            if (ddf instanceof C1696Dds) {
                return A4l.LIZ.LIZ(((C1696Dds) ddf).LIZIZ);
            }
            throw new 7AW();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:11:0x002c  */
    /* JADX WARNING: Removed duplicated region for block: B:7:0x001c  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final java.lang.Object whenRefresh(X.4r1<? super X.C1683Ddf<ITEM>> r6) {
        /*
            r5 = this;
            boolean r0 = r6 instanceof X.C1693Ddp
            if (r0 == 0) goto L_0x003c
            r4 = r6
            X.Ddp r4 = (X.C1693Ddp) r4
            int r0 = r4.label
            r1 = -2147483648(0xffffffff80000000, float:-0.0)
            r0 = r0 & r1
            if (r0 == 0) goto L_0x003c
            int r0 = r4.label
            int r0 = r0 - r1
            r4.label = r0
        L_0x0013:
            java.lang.Object r3 = r4.result
            X.Cof r2 = X.C0213Cof.COROUTINE_SUSPENDED
            int r0 = r4.label
            r1 = 1
            if (r0 == 0) goto L_0x002c
            if (r0 != r1) goto L_0x0042
            java.lang.Object r0 = r4.L$0
            com.bytedance.ext_power_list.AssemListViewModel r0 = (com.bytedance.ext_power_list.AssemListViewModel) r0
            X.2th.LIZ(r3)
        L_0x0025:
            X.A4l r3 = (X.A4l) r3
            X.Ddf r0 = r0.toResult(r3, r1)
            return r0
        L_0x002c:
            X.2th.LIZ(r3)
            r4.L$0 = r5
            r4.label = r1
            java.lang.Object r3 = r5.onRefresh(r4)
            if (r3 != r2) goto L_0x003a
            return r2
        L_0x003a:
            r0 = r5
            goto L_0x0025
        L_0x003c:
            X.Ddp r4 = new X.Ddp
            r4.<init>(r5, r6)
            goto L_0x0013
        L_0x0042:
            java.lang.IllegalStateException r1 = new java.lang.IllegalStateException
            java.lang.String r0 = "call to 'resume' before 'invoke' with coroutine"
            r1.<init>(r0)
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.ext_power_list.AssemListViewModel.whenRefresh(X.4r1):java.lang.Object");
    }

    public void listAddAllAt(int i, Collection<? extends ITEM> collection) {
        M12.LIZ(collection);
        withState(new C1678Dda(this, i, collection));
    }

    public void listAddItemAt(int i, ITEM item) {
        M12.LIZ(item);
        withState(new C1680Ddc(this, i, item));
    }

    public void listSetItemAt(int i, ITEM item) {
        M12.LIZ(item);
        withState(new C1681Ddd(this, i, item));
    }

    public final void modifyListState(S s, C1676DdY<ITEM> ddY) {
        newState(DWM.LIZ(s.getListState(), (4h3) null, (4h3) null, (4h3) null, ddY.LIZJ(), 7));
    }

    public C1683Ddf<ITEM> toResult(A4l<Cursor> a4l, boolean z) {
        M12.LIZ(a4l);
        if (a4l instanceof A4p) {
            A4p a4p = (A4p) a4l;
            return C1683Ddf.LIZ.LIZ(a4p.LIZIZ, a4p.LIZJ, a4p.LIZLLL);
        } else if (a4l instanceof A4m) {
            return C1683Ddf.LIZ.LIZ((Throwable) ((A4m) a4l).LIZIZ);
        } else {
            if (a4l instanceof A4o) {
                return C1683Ddf.LIZ.LIZ(((A4o) a4l).LIZIZ);
            }
            throw new 7AW();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:11:0x002e  */
    /* JADX WARNING: Removed duplicated region for block: B:7:0x001c  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final java.lang.Object whenLoadLatest(Cursor r6, X.4r1<? super X.C1683Ddf<ITEM>> r7) {
        /*
            r5 = this;
            boolean r0 = r7 instanceof X.C1691Ddn
            if (r0 == 0) goto L_0x003e
            r2 = r7
            X.Ddn r2 = (X.C1691Ddn) r2
            int r0 = r2.label
            r1 = -2147483648(0xffffffff80000000, float:-0.0)
            r0 = r0 & r1
            if (r0 == 0) goto L_0x003e
            int r0 = r2.label
            int r0 = r0 - r1
            r2.label = r0
        L_0x0013:
            java.lang.Object r4 = r2.result
            X.Cof r1 = X.C0213Cof.COROUTINE_SUSPENDED
            int r0 = r2.label
            r3 = 1
            if (r0 == 0) goto L_0x002e
            if (r0 != r3) goto L_0x0044
            java.lang.Object r2 = r2.L$0
            com.bytedance.ext_power_list.AssemListViewModel r2 = (com.bytedance.ext_power_list.AssemListViewModel) r2
            X.2th.LIZ(r4)
        L_0x0025:
            X.A4l r4 = (X.A4l) r4
            r1 = 0
            r0 = 0
            X.Ddf r0 = toResult$default(r2, r4, r1, r3, r0)
            return r0
        L_0x002e:
            X.2th.LIZ(r4)
            r2.L$0 = r5
            r2.label = r3
            java.lang.Object r4 = r5.onLoadLatest(r6, r2)
            if (r4 != r1) goto L_0x003c
            return r1
        L_0x003c:
            r2 = r5
            goto L_0x0025
        L_0x003e:
            X.Ddn r2 = new X.Ddn
            r2.<init>(r5, r7)
            goto L_0x0013
        L_0x0044:
            java.lang.IllegalStateException r1 = new java.lang.IllegalStateException
            java.lang.String r0 = "call to 'resume' before 'invoke' with coroutine"
            r1.<init>(r0)
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.ext_power_list.AssemListViewModel.whenLoadLatest(java.lang.Object, X.4r1):java.lang.Object");
    }

    /* JADX WARNING: Removed duplicated region for block: B:11:0x002e  */
    /* JADX WARNING: Removed duplicated region for block: B:7:0x001c  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final java.lang.Object whenLoadMore(Cursor r6, X.4r1<? super X.C1683Ddf<ITEM>> r7) {
        /*
            r5 = this;
            boolean r0 = r7 instanceof X.C1692Ddo
            if (r0 == 0) goto L_0x003e
            r2 = r7
            X.Ddo r2 = (X.C1692Ddo) r2
            int r0 = r2.label
            r1 = -2147483648(0xffffffff80000000, float:-0.0)
            r0 = r0 & r1
            if (r0 == 0) goto L_0x003e
            int r0 = r2.label
            int r0 = r0 - r1
            r2.label = r0
        L_0x0013:
            java.lang.Object r4 = r2.result
            X.Cof r1 = X.C0213Cof.COROUTINE_SUSPENDED
            int r0 = r2.label
            r3 = 1
            if (r0 == 0) goto L_0x002e
            if (r0 != r3) goto L_0x0044
            java.lang.Object r2 = r2.L$0
            com.bytedance.ext_power_list.AssemListViewModel r2 = (com.bytedance.ext_power_list.AssemListViewModel) r2
            X.2th.LIZ(r4)
        L_0x0025:
            X.A4l r4 = (X.A4l) r4
            r1 = 0
            r0 = 0
            X.Ddf r0 = toResult$default(r2, r4, r1, r3, r0)
            return r0
        L_0x002e:
            X.2th.LIZ(r4)
            r2.L$0 = r5
            r2.label = r3
            java.lang.Object r4 = r5.onLoadMore(r6, r2)
            if (r4 != r1) goto L_0x003c
            return r1
        L_0x003c:
            r2 = r5
            goto L_0x0025
        L_0x003e:
            X.Ddo r2 = new X.Ddo
            r2.<init>(r5, r7)
            goto L_0x0013
        L_0x0044:
            java.lang.IllegalStateException r1 = new java.lang.IllegalStateException
            java.lang.String r0 = "call to 'resume' before 'invoke' with coroutine"
            r1.<init>(r0)
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.ext_power_list.AssemListViewModel.whenLoadMore(java.lang.Object, X.4r1):java.lang.Object");
    }

    public void listSetItemsAt(int i, int i2, Collection<? extends ITEM> collection) {
        M12.LIZ(collection);
        withState(new C1677DdZ(this, i, i2, collection));
    }

    public static /* synthetic */ C1683Ddf toResult$default(AssemListViewModel assemListViewModel, A4l a4l, boolean z, int i, Object obj) {
        if (obj == null) {
            if ((i & 1) != 0) {
                z = false;
            }
            return assemListViewModel.toResult(a4l, z);
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: toResult");
    }
}
