package com.adobe.marketing.mobile.identity;

import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import wg.i0;
import wg.r;
import wg.t;
import wg.w;
import wg.x;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes4.dex */
public class m implements wg.l {

    /* renamed from: a, reason: collision with root package name */
    private final IdentityExtension f12283a;

    /* renamed from: b, reason: collision with root package name */
    private final int f12284b = 30;

    /* JADX INFO: Access modifiers changed from: package-private */
    public m(IdentityExtension identityExtension) {
        this.f12283a = identityExtension;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void e(k kVar, wg.m mVar, wg.o oVar) {
        if (oVar == null) {
            t.a("Identity", "IdentityHitsProcessing", "IdentityHitsDatabase.process : An unknown error occurred during the Identity network call, connection is null. Will not retry.", new Object[0]);
            this.f12283a.Z(null, kVar.b());
            mVar.a(true);
            return;
        }
        if (oVar.d() == 200) {
            try {
                n d10 = d(new JSONObject(ch.i.a(oVar.c())));
                t.e("Identity", "IdentityHitsProcessing", "IdentityHitsDatabase.process : ECID Service response data was parsed successfully.", new Object[0]);
                this.f12283a.Z(d10, kVar.b());
                mVar.a(true);
            } catch (JSONException e10) {
                t.a("Identity", "IdentityHitsProcessing", "IdentityHitsDatabase.process : An unknown exception occurred while trying to process the response from the ECID Service: (%s).", e10);
                mVar.a(false);
            }
        } else if (o.f12291a.contains(Integer.valueOf(oVar.d()))) {
            t.a("Identity", "IdentityHitsProcessing", "IdentityHitsDatabase.process : A recoverable network error occurred with response code %d while processing ECID Service requests.  Will retry in 30 seconds.", Integer.valueOf(oVar.d()));
            mVar.a(false);
        } else {
            t.a("Identity", "IdentityHitsProcessing", "IdentityHitsDatabase.process : Discarding ECID Service request because of an un-recoverable network error with response code %d occurred while processing it.", Integer.valueOf(oVar.d()));
            this.f12283a.Z(null, kVar.b());
            mVar.a(true);
        }
        oVar.close();
    }

    @Override // wg.l
    public int a(wg.d dVar) {
        return 30;
    }

    @Override // wg.l
    public void b(wg.d dVar, wg.m mVar) {
        f(dVar, 2, mVar);
    }

    n d(JSONObject jSONObject) {
        if (jSONObject == null) {
            t.a("Identity", "IdentityHitsProcessing", "createIdentityObjectFromResponseJsonObject: Unable to parse identity network response because the JSON object created was null.", new Object[0]);
            return null;
        }
        n nVar = new n();
        nVar.f12285a = jSONObject.optString("d_blob", null);
        nVar.f12288d = jSONObject.optString("error_msg", null);
        nVar.f12286b = jSONObject.optString("d_mid", null);
        int optInt = jSONObject.optInt("dcs_region", -1);
        nVar.f12287c = optInt != -1 ? Integer.toString(optInt) : null;
        nVar.f12289e = jSONObject.optLong("id_sync_ttl", 600L);
        JSONArray optJSONArray = jSONObject.optJSONArray("d_optout");
        if (optJSONArray != null) {
            ArrayList arrayList = new ArrayList();
            for (int i10 = 0; i10 < optJSONArray.length(); i10++) {
                try {
                    arrayList.add(optJSONArray.getString(i10));
                } catch (JSONException e10) {
                    t.a("Identity", "IdentityHitsProcessing", "createIdentityObjectFromResponseJsonObject : Unable to read opt-out JSON array due to an exception: (%s).", e10);
                }
            }
            nVar.f12290f = arrayList;
        }
        return nVar;
    }

    public void f(wg.d dVar, int i10, final wg.m mVar) {
        final k a10 = k.a(dVar);
        if (a10 == null) {
            mVar.a(true);
            return;
        }
        if (a10.c() == null || a10.b() == null) {
            t.a("Identity", "IdentityHitsProcessing", "IdentityHitsDatabase.process : Unable to process IdentityExtension hit because it does not contain a url or the trigger event.", new Object[0]);
            mVar.a(true);
        } else {
            t.a("Identity", "IdentityHitsProcessing", "IdentityHitsDatabase.process : Sending request: (%s).", a10.c());
            i0.f().h().a(new x(a10.c(), r.GET, null, o.a(true), i10, i10), new w() { // from class: com.adobe.marketing.mobile.identity.l
                @Override // wg.w
                public final void a(wg.o oVar) {
                    m.this.e(a10, mVar, oVar);
                }
            });
        }
    }
}
