package com.bytedance.android.livesdk.feed.repository;

import X.0Ay;
import X.0BA;
import X.0CB;
import X.0CH;
import X.0UK;
import X.0aH;
import X.0aJ;
import X.0af;
import X.0aj;
import X.0cE;
import X.1LV;
import X.1LW;
import X.1LX;
import X.1jW;
import X.6Is;
import X.86a;
import X.C3565GuM;
import X.C3575GuW;
import X.C3610Gv5;
import X.C3682GwF;
import X.C3725Gww;
import X.C3728Gwz;
import X.C3758GxT;
import X.C3761GxW;
import X.C3771Gxg;
import X.C3777Gxm;
import X.C3796Gy5;
import X.C3797Gy6;
import X.C3803GyC;
import X.C3818GyR;
import X.C3825GyY;
import X.C3837Gyk;
import X.OJw;
import X.PgU;
import X.Pm5;
import android.text.TextUtils;
import android.util.Pair;
import com.bytedance.android.live.base.model.ImageModel;
import com.bytedance.android.live.base.model.feed.FeedExtra;
import com.bytedance.android.live.core.feed.FeedApi;
import com.bytedance.android.livesdk.feed.feed.FeedDataKey;
import com.bytedance.android.livesdk.model.FeedItem;
import com.bytedance.covode.number.Covode;
import java.util.List;

public class FeedRepository extends BaseFeedRepository implements C3610Gv5, C3728Gwz, 6Is {
    public final FeedApi LJ;
    public final 0aH<FeedDataKey, FeedExtra> LJFF;
    public C3771Gxg LJI;
    public C3797Gy6<0cE<FeedItem>, C3761GxW> LJII;
    public OJw<Object> LJIIIIZZ = new OJw<>();
    public OJw<String> LJIIIZ = new OJw<>();
    public OJw<List<ImageModel>> LJIIJ = new OJw<>();
    public OJw<Pair<String, String>> LJIIJJI = new OJw<>();
    public OJw<String> LJIIL;
    public final C3825GyY LJIILIIL;
    public 0cE<FeedItem> LJIILJJIL;
    public int LJIILL;
    public final 0aH<Long, Integer> LJIILLIIL;
    public C3725Gww LJIIZILJ;
    public C3565GuM LJIJ;
    public String LJIJI;
    public C3837Gyk LJIJJ;
    public String LJIJJLI;

    static {
        Covode.recordClassIndex(16160);
    }

    public void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final PgU<String> LIZ() {
        return this.LJIIIZ;
    }

    public final PgU<List<ImageModel>> LIZIZ() {
        return this.LJIIJ;
    }

    public final C3725Gww LIZLLL() {
        return this.LJIIZILJ;
    }

    public final List<FeedItem> LJ() {
        return this.LIZIZ.LIZIZ(LJII());
    }

    private int LJIIIIZZ() {
        C3771Gxg gxg = this.LJI;
        if (gxg == null || gxg.LIZIZ() <= 0) {
            return 12;
        }
        return this.LJI.LIZIZ();
    }

    public final void LIZJ() {
        if (this.LIZ != null) {
            LJII();
            TextUtils.equals(this.LJIJI, "enter_auto");
            LJII();
        }
    }

    public final void LJFF() {
        this.LIZIZ.LIZLLL(LJII());
        C3565GuM guM = this.LJIJ;
        if (guM != null) {
            guM.LJIIJ.LIZ();
        }
    }

    public final void LJI() {
        this.LIZIZ.LIZLLL(LJII());
        if (this.LJIILJJIL != null) {
            0UK.LJII.LIZLLL();
            this.LJIILJJIL.LJFF();
        }
    }

    public final FeedDataKey LJII() {
        C3771Gxg gxg = this.LJI;
        if (gxg != null) {
            return gxg.LIZ();
        }
        throw new IllegalStateException("not call init() or params be null");
    }

    public final void LIZ(C3771Gxg gxg) {
        this.LJI = gxg;
    }

    public final void LIZIZ(String str) {
        this.LJIJJLI = str;
    }

    public final /* synthetic */ void LIZ(0aj r3) {
        OJw<Object> oJw;
        if (r3 != null && r3.LIZ == 0af.SUCCESS && (oJw = this.LJIIIIZZ) != null) {
            oJw.onNext(Pm5.LIZJ);
        }
    }

    public final FeedItem LIZLLL(String str) {
        return (FeedItem) this.LIZIZ.LIZ(LJII(), new C3758GxT(str));
    }

    public final void LIZJ(String str) {
        FeedItem LIZLLL = LIZLLL(str);
        if (LIZLLL != null) {
            this.LIZIZ.LIZ(LJII(), LIZLLL);
        }
        0cE<FeedItem> r0 = this.LJIILJJIL;
        if (r0 != null) {
            r0.LJII();
        }
    }

    public final C3797Gy6<0cE<FeedItem>, C3761GxW> LIZ(String str) {
        String str2;
        int i;
        LIZ(this.LJFF.LIZ(this.LJI.LIZ()).LIZLLL(C3682GwF.LIZ));
        FeedApi feedApi = this.LJ;
        C3825GyY gyY = this.LJIILIIL;
        C3725Gww gww = this.LJIIZILJ;
        OJw<Pair<String, String>> oJw = this.LJIIJJI;
        OJw<String> oJw2 = this.LJIIL;
        OJw<String> oJw3 = this.LJIIIZ;
        if (!86a.LIZ(this.LJIJJLI)) {
            str2 = this.LJIJJLI;
        } else {
            str2 = "enter_auto";
        }
        String str3 = str;
        this.LJIJ = new C3565GuM(str3, feedApi, gyY, gww, oJw, this, oJw2, oJw3, str2, new C3803GyC(this), this.LJIJJ, this.LJI.LIZ(), this.LJIIJ);
        1LX r5 = new 1LX();
        r5.LJIILJJIL = this.LJIJ;
        r5.LJIIJ = this.LJI.LIZ();
        0aJ<FeedDataKey, FeedItem> r1 = this.LIZIZ;
        0aH<FeedDataKey, FeedExtra> r0 = this.LJFF;
        r5.LJIIJJI = r1;
        r5.LJIIL = r0;
        0BA r12 = new 0BA();
        r12.LIZLLL = false;
        r12.LIZ = LJIIIIZZ();
        r12.LIZJ = LJIIIIZZ();
        C3771Gxg gxg = this.LJI;
        if (gxg == null || gxg.LIZJ() <= 0) {
            i = 4;
        } else {
            i = this.LJI.LIZJ();
        }
        r12.LIZIZ = i;
        r5.LJIILIIL = r12.LIZ();
        1LW r4 = new 1LW(r5);
        1LV r3 = new 1LV(r5.LIZJ, r5.LIZLLL);
        0Ay r13 = new 0Ay(r4, r5.LJIILIIL);
        r13.LIZ = r3;
        1jW r32 = new 1jW(r5, r13.LIZ());
        this.LJII = new C3797Gy6<>(r32, new C3761GxW());
        this.LJIILJJIL = r32;
        r32.LIZJ().observeForever(new C3777Gxm(this));
        return this.LJII;
    }

    public final void LIZ(String str, String str2) {
        this.LJIIJJI.onNext(new Pair(str, str2));
    }

    public FeedRepository(C3725Gww gww, FeedApi feedApi, 0aH<FeedDataKey, FeedExtra> r6, 0aJ<FeedDataKey, FeedItem> r7, 0aH<Long, Integer> r8, C3825GyY gyY, C3837Gyk gyk) {
        super(gww, r7);
        OJw<String> oJw = new OJw<>();
        this.LJIIL = oJw;
        this.LJIILL = -1;
        this.LJIJJLI = null;
        this.LJIIZILJ = gww;
        this.LJ = feedApi;
        this.LJFF = r6;
        this.LJIILLIIL = r8;
        this.LJIILIIL = gyY;
        this.LJIJJ = gyk;
        LIZ(oJw.LIZ(new C3796Gy5(this), C3818GyR.LIZ));
        LIZ(r7.LIZ().LIZLLL(C3575GuW.LIZ));
    }
}
