package com.bytedance.sdk.openadsdk.component.reward;

import android.os.SystemClock;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.utils.bx;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class duv {
    private boolean ajl;
    private final fm fm;
    private boolean jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private long f6897lb;
    private long ro;
    private final JSONObject wsy;
    private long yz;

    public interface fm {
        void fm(int i10, boolean z10);
    }

    public duv(fm fmVar) {
        this.jnr = true;
        this.fm = fmVar;
        JSONObject jSONObject = (JSONObject) com.bytedance.sdk.openadsdk.hlt.jnr.fm("reward_callback_backup", (Object) null, com.bytedance.sdk.openadsdk.hlt.ro.fm);
        this.wsy = jSONObject;
        if (jSONObject == null) {
            return;
        }
        this.jnr = false;
    }

    public static void fm(lse lseVar, boolean z10, final int i10) {
        com.bytedance.sdk.openadsdk.yz.lb.fm(System.currentTimeMillis(), lseVar, bx.fm(lseVar), z10 ? "reward_callback" : "reward_fail_callback", new com.bytedance.sdk.openadsdk.irt.ro.fm() { // from class: com.bytedance.sdk.openadsdk.component.reward.duv.1
            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject fm() {
                try {
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put("reason", i10);
                    return jSONObject;
                } catch (Throwable unused) {
                    return null;
                }
            }
        });
    }

    public void lb() {
        this.jnr = true;
    }

    public void ro() {
        if (this.jnr) {
            return;
        }
        this.f6897lb = SystemClock.elapsedRealtime();
    }

    public void yz() {
        JSONObject jSONObject;
        if (this.fm != null) {
            long jElapsedRealtime = (this.yz + (this.f6897lb > 0 ? SystemClock.elapsedRealtime() - this.f6897lb : 0L)) / 1000;
            if (this.jnr || (jSONObject = this.wsy) == null || "off".equals(jSONObject.optString("type"))) {
                return;
            }
            if ("force".equals(this.wsy.optString("type"))) {
                if (jElapsedRealtime >= this.wsy.optInt("value", -1)) {
                    this.ajl = true;
                    this.fm.fm(1, true);
                    return;
                }
                return;
            }
            if ("normal".equals(this.wsy.optString("type"))) {
                int iOptInt = this.wsy.optInt("value", -1);
                if (iOptInt < 0 && jElapsedRealtime >= this.ro) {
                    this.ajl = false;
                    this.fm.fm(1, false);
                } else {
                    if (iOptInt < 0 || jElapsedRealtime < iOptInt) {
                        return;
                    }
                    this.ajl = false;
                    this.fm.fm(1, false);
                }
            }
        }
    }

    public void fm(long j10) {
        if (j10 <= this.ro) {
            return;
        }
        this.ro = Math.min(30L, j10);
    }

    public void fm() {
        if (!this.jnr && this.f6897lb > 0) {
            this.yz = (SystemClock.elapsedRealtime() - this.f6897lb) + this.yz;
            this.f6897lb = 0L;
        }
    }
}
