package com.bytedance.sdk.openadsdk.duv.fm;

import com.bytedance.sdk.openadsdk.core.hxv;
import com.bytedance.sdk.openadsdk.core.model.lse;
import java.lang.ref.WeakReference;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class ajl extends com.bytedance.sdk.component.fm.yz<JSONObject, JSONObject> {
    private final WeakReference<hxv> fm;

    public ajl(hxv hxvVar) {
        this.fm = new WeakReference<>(hxvVar);
    }

    public static void fm(com.bytedance.sdk.component.fm.fhx fhxVar, hxv hxvVar) {
        fhxVar.fm("interactiveFinish", new ajl(hxvVar));
    }

    @Override // com.bytedance.sdk.component.fm.yz
    public JSONObject fm(String str, JSONObject jSONObject, com.bytedance.sdk.component.fm.jnr jnrVar) throws Exception {
        JSONObject jSONObject2 = new JSONObject();
        WeakReference<hxv> weakReference = this.fm;
        if (weakReference != null && weakReference.get() != null) {
            hxv hxvVar = this.fm.get();
            lse lseVarYz = hxvVar.yz();
            try {
                boolean z10 = true;
                int i10 = 0;
                if (jSONObject.optInt("finish", 1) != 1) {
                    z10 = false;
                }
                int iOptInt = jSONObject.optInt("reduce_duration", -1);
                int iRr = lseVarYz != null ? lseVarYz.rr() : 0;
                if (iOptInt >= 0 && iRr >= 0) {
                    iOptInt = Math.min(iOptInt, iRr);
                } else if (iOptInt < 0) {
                    iOptInt = iRr >= 0 ? iRr : 0;
                }
                if (z10) {
                    hxvVar.lb(iOptInt);
                } else {
                    i10 = -1;
                }
                jSONObject2.put("code", i10);
                jSONObject2.put("reduce_duration", iOptInt);
            } catch (JSONException e10) {
                com.bytedance.sdk.component.utils.wey.lb("InteractiveFinishMethod", e10.getMessage());
            }
        }
        return jSONObject2;
    }
}
