package g7;

import android.os.Bundle;
import android.os.RemoteException;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import n7.h4;
import n7.m2;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f26313a = new ArrayList();

    @Nullable
    private final m2 zza;

    @Nullable
    private i zzc;

    private u(@Nullable m2 m2Var) {
        this.zza = m2Var;
        if (m2Var != null) {
            try {
                List listZzg = m2Var.zzg();
                if (listZzg != null) {
                    Iterator it = listZzg.iterator();
                    while (it.hasNext()) {
                        i iVarZza = i.zza((h4) it.next());
                        if (iVarZza != null) {
                            this.f26313a.add(iVarZza);
                        }
                    }
                }
            } catch (RemoteException unused) {
            }
        }
        m2 m2Var2 = this.zza;
        if (m2Var2 == null) {
            return;
        }
        try {
            h4 h4VarZzh = m2Var2.zzh();
            if (h4VarZzh != null) {
                this.zzc = i.zza(h4VarZzh);
            }
        } catch (RemoteException unused2) {
        }
    }

    @Nullable
    public static u zzb(@Nullable m2 m2Var) {
        if (m2Var != null) {
            return new u(m2Var);
        }
        return null;
    }

    @NonNull
    public static u zzc(@Nullable m2 m2Var) {
        return new u(m2Var);
    }

    public final JSONObject a() throws JSONException {
        m2 m2Var;
        JSONObject jSONObject = new JSONObject();
        String responseId = getResponseId();
        if (responseId == null) {
            jSONObject.put("Response ID", "null");
        } else {
            jSONObject.put("Response ID", responseId);
        }
        String mediationAdapterClassName = getMediationAdapterClassName();
        if (mediationAdapterClassName == null) {
            jSONObject.put("Mediation Adapter Class Name", "null");
        } else {
            jSONObject.put("Mediation Adapter Class Name", mediationAdapterClassName);
        }
        JSONArray jSONArray = new JSONArray();
        Iterator it = this.f26313a.iterator();
        while (it.hasNext()) {
            jSONArray.put(((i) it.next()).a());
        }
        jSONObject.put("Adapter Responses", jSONArray);
        i iVar = this.zzc;
        if (iVar != null) {
            jSONObject.put("Loaded Adapter Response", iVar.a());
        }
        try {
            m2Var = this.zza;
        } catch (RemoteException unused) {
        }
        Bundle bundleZzi = m2Var != null ? m2Var.zzi() : new Bundle();
        if (bundleZzi != null) {
            jSONObject.put("Response Extras", n7.x.f31085g.f31086a.d(bundleZzi));
        }
        return jSONObject;
    }

    @Nullable
    public i getLoadedAdapterResponseInfo() {
        return this.zzc;
    }

    @Nullable
    public String getMediationAdapterClassName() {
        try {
            m2 m2Var = this.zza;
            if (m2Var != null) {
                return m2Var.zze();
            }
            return null;
        } catch (RemoteException unused) {
            return null;
        }
    }

    @Nullable
    public String getResponseId() {
        try {
            m2 m2Var = this.zza;
            if (m2Var != null) {
                return m2Var.zzf();
            }
            return null;
        } catch (RemoteException unused) {
            return null;
        }
    }

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

    @Nullable
    public final m2 zzd() {
        return this.zza;
    }
}
