package com.bytedance.android.live.wallet;

import X.2YN;
import X.9sP;
import X.AnonymousClass0UM;
import X.AnonymousClass17M;
import X.AnonymousClass1JF;
import X.C24850yx;
import X.C24970z9;
import X.C36151c5;
import X.C38601g2;
import X.C38631g5;
import X.C38641g6;
import X.C38651g7;
import X.C40601jG;
import X.Gu9;
import X.H7d;
import X.HUl;
import X.Hzs;
import X.Mha;
import X.Mk2;
import X.Mk3;
import X.OJw;
import X.PgU;
import android.os.SystemClock;
import com.bytedance.android.live.wallet.api.IapApi;
import com.bytedance.android.live.wallet.model.BalanceStruct;
import com.bytedance.android.live.wallet.model.BalanceStructExtra;
import com.bytedance.android.live.walletnew.BaseRechargeViewModel;
import com.bytedance.covode.number.Covode;
import java.util.HashMap;
import java.util.Map;

public class WalletCenter implements IWalletCenter {
    public AnonymousClass17M LIZ;
    public BalanceStruct LIZIZ;
    public final Mha<Long> LIZJ;

    static {
        Covode.recordClassIndex(10788);
    }

    public void onInit() {
    }

    public final BalanceStruct LIZLLL() {
        return this.LIZIZ;
    }

    public final AnonymousClass17M LJ() {
        return this.LIZ;
    }

    private boolean LJIIIIZZ() {
        return H7d.LIZ().LIZIZ().LJ();
    }

    public final PgU<Long> LIZ() {
        return this.LIZJ.LIZ(Mk2.LIZ(Mk3.LIZ));
    }

    public final long LIZIZ() {
        if (!LJIIIIZZ()) {
            return 0;
        }
        return this.LIZ.LIZ;
    }

    public final void LJII() {
        this.LIZIZ = new BalanceStruct();
        this.LIZ = new AnonymousClass17M();
    }

    public WalletCenter() {
        this.LIZ = new AnonymousClass17M();
        this.LIZIZ = new BalanceStruct();
        this.LIZJ = new OJw();
    }

    public final boolean LJFF() {
        AnonymousClass17M r0;
        if (LJIIIIZZ() && (r0 = this.LIZ) != null && r0.LJ == 1) {
            return true;
        }
        return false;
    }

    public final void LIZJ() {
        if (LJIIIIZZ()) {
            long uptimeMillis = SystemClock.uptimeMillis();
            ((IapApi) C24850yx.LIZ().LIZ(IapApi.class)).getWalletInfoNew().LIZ(new Hzs()).LIZ(new C38601g2(this, uptimeMillis), new C38631g5(uptimeMillis));
        }
    }

    public final void LJI() {
        if (LJIIIIZZ()) {
            ((IapApi) C24850yx.LIZ().LIZ(IapApi.class)).getBalanceInfo(1).LIZ(new Hzs()).LIZ(new C38641g6(this), C38651g7.LIZ);
        }
    }

    public /* synthetic */ WalletCenter(byte b) {
        this();
    }

    public final void LIZ(long j) {
        if (LJIIIIZZ()) {
            this.LIZ.LIZ = j;
            this.LIZJ.onNext(Long.valueOf(LIZIZ()));
        }
    }

    public final boolean LIZIZ(long j) {
        if (LJIIIIZZ() && this.LIZ.LIZ >= j) {
            return true;
        }
        return false;
    }

    public final void LIZ(final 9sP r6) {
        if (!LJIIIIZZ()) {
            AnonymousClass1JF r1 = new AnonymousClass1JF(-666);
            r1.setErrorMsg("user doesn't login");
            r6.LIZ(r1);
            return;
        }
        final long uptimeMillis = SystemClock.uptimeMillis();
        ((IapApi) C24850yx.LIZ().LIZ(IapApi.class)).getWalletInfoNew().LIZ(new Hzs()).LIZ(new 2YN<C36151c5<AnonymousClass17M>>() {
            static {
                Covode.recordClassIndex(10789);
            }

            public final /* synthetic */ void accept(Object obj) {
                C24970z9 r6 = (C24970z9) obj;
                if (r6.data != null) {
                    WalletCenter.this.LIZ = (AnonymousClass17M) r6.data;
                    BalanceStructExtra balanceStructExtra = WalletCenter.this.LIZ.LIZLLL;
                    WalletExchange.LIZ.LIZ(((AnonymousClass17M) r6.data).LIZ());
                    WalletExchange.LIZ.LIZIZ(((AnonymousClass17M) r6.data).LIZIZ());
                    if (WalletCenter.this.LIZ.LIZJ != null && WalletCenter.this.LIZ.LIZJ.getEnableExchange()) {
                        WalletCenter.this.LIZ.LIZLLL = balanceStructExtra;
                        WalletExchange.LIZ.LIZ(WalletCenter.this.LIZ.LIZJ.getCurrency(), WalletCenter.this.LIZ.LIZJ.getRegion(), WalletCenter.this.LIZ.LIZJ.getBalance());
                    }
                    r6.LIZ(((AnonymousClass17M) r6.data).LIZ);
                    WalletCenter.this.LIZJ.onNext(Long.valueOf(WalletCenter.this.LIZIZ()));
                } else {
                    r6.LIZ(new C40601jG());
                }
                Gu9.LIZ(0, SystemClock.uptimeMillis() - uptimeMillis, (Map) null);
            }
        }, new 2YN<Throwable>() {
            static {
                Covode.recordClassIndex(10790);
            }

            public final /* synthetic */ void accept(Object obj) {
                int i;
                Throwable th = (Throwable) obj;
                HashMap hashMap = new HashMap();
                hashMap.put("error_msg", th.getMessage());
                if (th instanceof AnonymousClass0UM) {
                    i = ((AnonymousClass0UM) th).getErrorCode();
                } else {
                    i = -16;
                }
                hashMap.put("error_code", Integer.valueOf(i));
                Gu9.LIZ(SystemClock.uptimeMillis() - uptimeMillis, hashMap);
                Gu9.LIZ(1, SystemClock.uptimeMillis() - uptimeMillis, hashMap);
                r6.LIZ(th);
            }
        });
    }

    public final void LIZ(long j, long j2) {
        new BaseRechargeViewModel((HUl) null, j, j2).LIZJ();
    }
}
