package com.bytedance.android.live.walletnew;

import X.0Bt;
import X.0cm;
import X.0yx;
import X.16u;
import X.16w;
import X.16y;
import X.2cN;
import X.7vl;
import X.86a;
import X.C4699HUe;
import X.C4700HUf;
import X.C4701HUg;
import X.C4702HUh;
import X.C4706HUl;
import X.C4792HXt;
import X.C6455Hzs;
import X.Crj;
import X.HV4;
import X.M12;
import android.app.Activity;
import com.bytedance.android.live.wallet.IWalletCenter;
import com.bytedance.android.live.wallet.IWalletService;
import com.bytedance.android.live.wallet.api.IapApi;
import com.bytedance.android.livesdk.wallet.Diamond;
import com.bytedance.android.livesdk.wallet.DiamondPackageExtra;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.List;
import kotlin.h.b.n;

public class BaseRechargeViewModel extends 0Bt {
    public DiamondPackageExtra LIZ;
    public List<Diamond> LIZIZ;
    public Diamond LIZJ;
    public final 16w LIZLLL = new C4699HUe(this);
    public C4706HUl LJ;
    public final long LJFF;
    public final long LJI;
    public final Crj LJII = 7vl.LIZ(HV4.LIZ);
    public 16u LJIIIIZZ;
    public 2cN LJIIIZ;

    static {
        Covode.recordClassIndex(10917);
    }

    public final String LIZ() {
        return (String) this.LJII.getValue();
    }

    public 16u LIZIZ() {
        return this.LJIIIIZZ;
    }

    public final long LJ() {
        IWalletCenter walletCenter = 0cm.LIZ(IWalletService.class).walletCenter();
        n.LIZIZ(walletCenter, "");
        return walletCenter.LIZIZ();
    }

    public void LJFF() {
        2cN r0;
        2cN r02 = this.LJIIIZ;
        if (!(r02 == null || r02.isDisposed() || (r0 = this.LJIIIZ) == null)) {
            r0.dispose();
        }
        this.LJ = null;
    }

    public final void LIZLLL() {
        this.LJIIIZ = ((IapApi) 0yx.LIZ().LIZ(IapApi.class)).fetchDiamondPackage(16y.LIZJ, this.LJFF, this.LJI, 16y.LJFF.LIZJ()).LIZ(new C6455Hzs()).LIZ(new C4700HUf(this), new C4702HUh(this));
    }

    public final void LIZJ() {
        List<Diamond> list;
        C4706HUl hUl;
        2cN r0;
        C4706HUl hUl2 = this.LJ;
        if (hUl2 != null) {
            hUl2.LIZIZ();
        }
        2cN r02 = this.LJIIIZ;
        if (!(r02 == null || r02.isDisposed() || (r0 = this.LJIIIZ) == null)) {
            r0.dispose();
        }
        if (16y.LJFF.LJ()) {
            C4706HUl hUl3 = this.LJ;
            if (hUl3 != null) {
                hUl3.LIZLLL();
            }
            16y r1 = 16y.LJFF;
            if (!r1.LJ()) {
                r1.LIZLLL();
                list = new ArrayList<>();
            } else {
                list = 16y.LJ;
            }
            this.LIZIZ = list;
            DiamondPackageExtra diamondPackageExtra = 16y.LIZLLL;
            this.LIZ = diamondPackageExtra;
            List<Diamond> list2 = this.LIZIZ;
            if (list2 != null && (hUl = this.LJ) != null) {
                hUl.LIZ(diamondPackageExtra, list2);
            }
        } else if (16y.LIZJ.length() != 0 || 16y.LJFF.LIZ()) {
            LIZLLL();
        } else {
            ArrayList arrayList = new ArrayList();
            arrayList.add(LIZ());
            C4792HXt.LIZ.LIZ(arrayList, this.LIZLLL);
        }
    }

    public void LIZ(16u r1) {
        this.LJIIIIZZ = r1;
    }

    public final Diamond LIZ(String str) {
        M12.LIZ(str);
        List<Diamond> list = this.LIZIZ;
        if (list == null) {
            return null;
        }
        for (Diamond diamond : list) {
            if (86a.LIZ(diamond.LIZIZ, str)) {
                return diamond;
            }
        }
        return null;
    }

    public final void LIZ(Diamond diamond) {
        M12.LIZ(diamond);
        0cm.LIZ(IWalletService.class).walletCenter().LIZ(new C4701HUg(diamond, LJ()));
    }

    public BaseRechargeViewModel(C4706HUl hUl, long j, long j2) {
        this.LJ = hUl;
        this.LJFF = j;
        this.LJI = j2;
    }

    public final void LIZ(Activity activity, Diamond diamond, int i) {
        M12.LIZ(diamond);
        this.LIZJ = diamond;
        C4706HUl hUl = this.LJ;
        if (hUl != null) {
            hUl.LIZIZ(2131833764);
        }
        C4792HXt.LIZ.LIZ(activity, diamond, this.LIZLLL, i);
    }
}
