package g7;

import android.os.Bundle;
import androidx.annotation.Nullable;
import n7.h4;
import n7.l2;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class i {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final h4 f26301a;

    @Nullable
    private final a zzb;

    public i(h4 h4Var) {
        this.f26301a = h4Var;
        l2 l2Var = h4Var.zzc;
        this.zzb = l2Var == null ? null : l2Var.w();
    }

    @Nullable
    public static i zza(@Nullable h4 h4Var) {
        if (h4Var != null) {
            return new i(h4Var);
        }
        return null;
    }

    public final JSONObject a() throws JSONException {
        JSONObject jSONObject = new JSONObject();
        h4 h4Var = this.f26301a;
        jSONObject.put("Adapter", h4Var.f30967a);
        jSONObject.put("Latency", h4Var.f30968b);
        String str = h4Var.f30970d;
        if (str == null) {
            jSONObject.put("Ad Source Name", "null");
        } else {
            jSONObject.put("Ad Source Name", str);
        }
        String str2 = h4Var.f30971e;
        if (str2 == null) {
            jSONObject.put("Ad Source ID", "null");
        } else {
            jSONObject.put("Ad Source ID", str2);
        }
        String str3 = h4Var.f30972f;
        if (str3 == null) {
            jSONObject.put("Ad Source Instance Name", "null");
        } else {
            jSONObject.put("Ad Source Instance Name", str3);
        }
        String str4 = h4Var.f30973g;
        if (str4 == null) {
            jSONObject.put("Ad Source Instance ID", "null");
        } else {
            jSONObject.put("Ad Source Instance ID", str4);
        }
        JSONObject jSONObject2 = new JSONObject();
        Bundle bundle = h4Var.f30969c;
        for (String str5 : bundle.keySet()) {
            jSONObject2.put(str5, bundle.get(str5));
        }
        jSONObject.put("Credentials", jSONObject2);
        a aVar = this.zzb;
        if (aVar == null) {
            jSONObject.put("Ad Error", "null");
        } else {
            jSONObject.put("Ad Error", aVar.b());
        }
        return jSONObject;
    }

    @Nullable
    public a getAdError() {
        return this.zzb;
    }

    public final String toString() {
        try {
            return a().toString(2);
        } catch (JSONException unused) {
            return "Error forming toString output.";
        }
    }
}
