package qg;

import ch.h;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventHistoryResultHandler;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.SharedStateResolution;
import com.adobe.marketing.mobile.SharedStateResolver;
import com.adobe.marketing.mobile.SharedStateResult;
import com.adobe.marketing.mobile.SharedStateStatus;
import com.adobe.marketing.mobile.WrapperType;
import com.adobe.marketing.mobile.internal.eventhub.EventHubPlaceholderExtension;
import com.google.android.gms.common.api.Api;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import kotlin.jvm.internal.o0;
import kotlin.jvm.internal.v;
import kotlin.text.y;
import rm.c0;
import rm.n0;
import rm.q;
import sm.p0;
import sm.q0;
import wg.t;

/* loaded from: classes4.dex */
public final class a {

    /* renamed from: a, reason: collision with root package name */
    private final rm.o f33691a;

    /* renamed from: b, reason: collision with root package name */
    private final rm.o f33692b;

    /* renamed from: c, reason: collision with root package name */
    private final ConcurrentHashMap f33693c;

    /* renamed from: d, reason: collision with root package name */
    private final ConcurrentLinkedQueue f33694d;

    /* renamed from: e, reason: collision with root package name */
    private final ConcurrentLinkedQueue f33695e;

    /* renamed from: f, reason: collision with root package name */
    private final AtomicInteger f33696f;

    /* renamed from: g, reason: collision with root package name */
    private final ConcurrentHashMap f33697g;

    /* renamed from: h, reason: collision with root package name */
    private final Set f33698h;

    /* renamed from: i, reason: collision with root package name */
    private boolean f33699i;

    /* renamed from: j, reason: collision with root package name */
    private dn.a f33700j;

    /* renamed from: k, reason: collision with root package name */
    private boolean f33701k;

    /* renamed from: l, reason: collision with root package name */
    private final h.c f33702l;

    /* renamed from: m, reason: collision with root package name */
    private final ch.h f33703m;

    /* renamed from: n, reason: collision with root package name */
    private rg.c f33704n;

    /* renamed from: o, reason: collision with root package name */
    private WrapperType f33705o;

    /* renamed from: q, reason: collision with root package name */
    public static final C0782a f33690q = new C0782a(null);

    /* renamed from: p, reason: collision with root package name */
    private static a f33689p = new a();

    /* renamed from: qg.a$a, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    public static final class C0782a {
        private C0782a() {
        }

        public /* synthetic */ C0782a(kotlin.jvm.internal.k kVar) {
            this();
        }

        public final a a() {
            return a.f33689p;
        }
    }

    /* loaded from: classes4.dex */
    static final class b implements Callable {

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ qg.m f33707b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ String f33708c;

        /* renamed from: d, reason: collision with root package name */
        final /* synthetic */ Event f33709d;

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: qg.a$b$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        public static final class C0783a implements SharedStateResolver {

            /* renamed from: b, reason: collision with root package name */
            final /* synthetic */ int f33711b;

            C0783a(int i10) {
                this.f33711b = i10;
            }

            @Override // com.adobe.marketing.mobile.SharedStateResolver
            public final void a(Map map) {
                b bVar = b.this;
                a.this.R(bVar.f33707b, bVar.f33708c, map, this.f33711b);
            }
        }

        b(qg.m mVar, String str, Event event) {
            this.f33707b = mVar;
            this.f33708c = str;
            this.f33709d = event;
        }

        @Override // java.util.concurrent.Callable
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final SharedStateResolver call() {
            qg.l K = a.this.K(this.f33707b, this.f33708c);
            if (K == null) {
                StringBuilder sb2 = new StringBuilder();
                sb2.append("Create pending ");
                sb2.append(this.f33707b);
                sb2.append(" shared state for extension \"");
                sb2.append(this.f33708c);
                sb2.append("\" for event ");
                Event event = this.f33709d;
                sb2.append(event != null ? event.x() : null);
                sb2.append(" failed - SharedStateManager is null");
                t.f("MobileCore", "EventHub", sb2.toString(), new Object[0]);
                return null;
            }
            int S = a.this.S(K, this.f33709d);
            if (K.e(S)) {
                t.a("MobileCore", "EventHub", "Created pending " + this.f33707b + " shared state for extension \"" + this.f33708c + "\" with version " + S, new Object[0]);
                return new C0783a(S);
            }
            StringBuilder sb3 = new StringBuilder();
            sb3.append("Create pending ");
            sb3.append(this.f33707b);
            sb3.append(" shared state for extension \"");
            sb3.append(this.f33708c);
            sb3.append("\" for event ");
            Event event2 = this.f33709d;
            sb3.append(event2 != null ? event2.x() : null);
            sb3.append(" failed - SharedStateManager failed");
            t.f("MobileCore", "EventHub", sb3.toString(), new Object[0]);
            return null;
        }
    }

    /* loaded from: classes4.dex */
    static final class c implements Callable {

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ qg.m f33713b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ String f33714c;

        /* renamed from: d, reason: collision with root package name */
        final /* synthetic */ Map f33715d;

        /* renamed from: e, reason: collision with root package name */
        final /* synthetic */ Event f33716e;

        c(qg.m mVar, String str, Map map, Event event) {
            this.f33713b = mVar;
            this.f33714c = str;
            this.f33715d = map;
            this.f33716e = event;
        }

        @Override // java.util.concurrent.Callable
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Boolean call() {
            return Boolean.valueOf(a.this.x(this.f33713b, this.f33714c, this.f33715d, this.f33716e));
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class d implements Runnable {

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ Event f33718q;

        d(Event event) {
            this.f33718q = event;
        }

        @Override // java.lang.Runnable
        public final void run() {
            a.this.z(this.f33718q);
        }
    }

    /* loaded from: classes4.dex */
    static final class e implements h.c {

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: qg.a$e$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        public static final class C0784a implements EventHistoryResultHandler {

            /* renamed from: b, reason: collision with root package name */
            final /* synthetic */ o0 f33721b;

            C0784a(o0 o0Var) {
                this.f33721b = o0Var;
            }

            @Override // com.adobe.marketing.mobile.EventHistoryResultHandler
            /* renamed from: b, reason: merged with bridge method [inline-methods] */
            public final void a(Boolean bool) {
                if (bool.booleanValue()) {
                    return;
                }
                t.a("MobileCore", "EventHub", "Failed to insert Event(" + ((Event) this.f33721b.f26199p).x() + ") into EventHistory database", new Object[0]);
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* loaded from: classes4.dex */
        public static final class b implements Runnable {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ Collection f33722p;

            /* renamed from: q, reason: collision with root package name */
            final /* synthetic */ o0 f33723q;

            b(Collection collection, o0 o0Var) {
                this.f33722p = collection;
                this.f33723q = o0Var;
            }

            @Override // java.lang.Runnable
            public final void run() {
                Iterator it = this.f33722p.iterator();
                if (it.hasNext()) {
                    android.support.v4.media.session.b.a(it.next());
                    throw null;
                }
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* loaded from: classes4.dex */
        public static final class c extends v implements dn.l {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ o0 f33724p;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            c(o0 o0Var) {
                super(1);
                this.f33724p = o0Var;
            }

            public final boolean a(qg.j jVar) {
                throw null;
            }

            @Override // dn.l
            public /* bridge */ /* synthetic */ Object invoke(Object obj) {
                android.support.v4.media.session.b.a(obj);
                return Boolean.valueOf(a(null));
            }
        }

        e() {
        }

        @Override // ch.h.c
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public final boolean a(Event event) {
            rg.c E;
            Collection b10;
            kotlin.jvm.internal.t.g(event, "event");
            o0 o0Var = new o0();
            o0Var.f26199p = event;
            Iterator it = a.this.f33695e.iterator();
            while (it.hasNext()) {
                o0Var.f26199p = ((qg.f) it.next()).a((Event) o0Var.f26199p);
            }
            if (((Event) o0Var.f26199p).s() != null) {
                b10 = qg.d.b(a.this.f33694d, new c(o0Var));
                a.this.B(new b(b10, o0Var));
            }
            Collection values = a.this.f33693c.values();
            kotlin.jvm.internal.t.f(values, "registeredExtensions.values");
            Iterator it2 = values.iterator();
            while (it2.hasNext()) {
                ((qg.g) it2.next()).s().n((Event) o0Var.f26199p);
            }
            if (t.c().compareTo(LoggingMode.DEBUG) >= 0) {
                t.a("MobileCore", "EventHub", "Dispatched Event #" + a.this.G(event) + " to extensions after processing rules - (" + ((Event) o0Var.f26199p) + ')', new Object[0]);
            }
            if (((Event) o0Var.f26199p).p() == null || (E = a.this.E()) == null) {
                return true;
            }
            E.b((Event) o0Var.f26199p, new C0784a(o0Var));
            return true;
        }
    }

    /* loaded from: classes4.dex */
    static final class f extends v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        public static final f f33725p = new f();

        f() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final ExecutorService invoke() {
            return Executors.newSingleThreadExecutor();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class g implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ Runnable f33726p;

        g(Runnable runnable) {
            this.f33726p = runnable;
        }

        @Override // java.lang.Runnable
        public final void run() {
            try {
                this.f33726p.run();
            } catch (Exception e10) {
                t.a("MobileCore", "EventHub", "Exception thrown from callback - " + e10, new Object[0]);
            }
        }
    }

    /* loaded from: classes4.dex */
    static final class h implements Callable {

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ String f33728b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ qg.m f33729c;

        /* renamed from: d, reason: collision with root package name */
        final /* synthetic */ Event f33730d;

        /* renamed from: e, reason: collision with root package name */
        final /* synthetic */ SharedStateResolution f33731e;

        /* renamed from: f, reason: collision with root package name */
        final /* synthetic */ boolean f33732f;

        h(String str, qg.m mVar, Event event, SharedStateResolution sharedStateResolution, boolean z10) {
            this.f33728b = str;
            this.f33729c = mVar;
            this.f33730d = event;
            this.f33731e = sharedStateResolution;
            this.f33732f = z10;
        }

        @Override // java.util.concurrent.Callable
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final SharedStateResult call() {
            SharedStateResult b10;
            qg.g H = a.this.H(this.f33728b);
            if (H == null) {
                t.a("MobileCore", "EventHub", "Unable to retrieve " + this.f33729c + " shared state for \"" + this.f33728b + "\". No such extension is registered.", new Object[0]);
                return null;
            }
            qg.l K = a.this.K(this.f33729c, this.f33728b);
            if (K == null) {
                t.f("MobileCore", "EventHub", "Unable to retrieve " + this.f33729c + " shared state for \"" + this.f33728b + "\". SharedStateManager is null", new Object[0]);
                return null;
            }
            Integer G = a.this.G(this.f33730d);
            int intValue = G != null ? G.intValue() : Api.BaseClientBuilder.API_PRIORITY_OTHER;
            int i10 = qg.b.f33755a[this.f33731e.ordinal()];
            if (i10 == 1) {
                b10 = K.b(intValue);
            } else {
                if (i10 != 2) {
                    throw new rm.t();
                }
                b10 = K.c(intValue);
            }
            Integer G2 = a.this.G(H.v());
            return (this.f33732f && !(this.f33730d == null || (G2 != null ? G2.intValue() : 0) > intValue - 1) && b10.a() == SharedStateStatus.SET) ? new SharedStateResult(SharedStateStatus.PENDING, b10.b()) : b10;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class i implements Runnable {

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ Class f33734q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ dn.l f33735r;

        /* renamed from: qg.a$i$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        static final class RunnableC0785a implements Runnable {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ dn.l f33736p;

            RunnableC0785a(dn.l lVar) {
                this.f33736p = lVar;
            }

            @Override // java.lang.Runnable
            public final void run() {
                this.f33736p.invoke(qg.c.DuplicateExtensionName);
            }
        }

        /* loaded from: classes4.dex */
        static final class b extends v implements dn.l {

            /* JADX INFO: Access modifiers changed from: package-private */
            /* renamed from: qg.a$i$b$a, reason: collision with other inner class name */
            /* loaded from: classes4.dex */
            public static final class RunnableC0786a implements Runnable {

                /* renamed from: q, reason: collision with root package name */
                final /* synthetic */ qg.c f33739q;

                /* renamed from: qg.a$i$b$a$a, reason: collision with other inner class name */
                /* loaded from: classes4.dex */
                static final class RunnableC0787a implements Runnable {

                    /* renamed from: p, reason: collision with root package name */
                    final /* synthetic */ dn.l f33740p;

                    /* renamed from: q, reason: collision with root package name */
                    final /* synthetic */ RunnableC0786a f33741q;

                    RunnableC0787a(dn.l lVar, RunnableC0786a runnableC0786a) {
                        this.f33740p = lVar;
                        this.f33741q = runnableC0786a;
                    }

                    @Override // java.lang.Runnable
                    public final void run() {
                        this.f33740p.invoke(this.f33741q.f33739q);
                    }
                }

                RunnableC0786a(qg.c cVar) {
                    this.f33739q = cVar;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    i iVar = i.this;
                    dn.l lVar = iVar.f33735r;
                    if (lVar != null) {
                        a.this.B(new RunnableC0787a(lVar, this));
                    }
                    i iVar2 = i.this;
                    a.this.C(iVar2.f33734q, this.f33739q);
                }
            }

            b() {
                super(1);
            }

            public final void a(qg.c error) {
                kotlin.jvm.internal.t.g(error, "error");
                a.this.F().submit(new RunnableC0786a(error));
            }

            @Override // dn.l
            public /* bridge */ /* synthetic */ Object invoke(Object obj) {
                a((qg.c) obj);
                return n0.f34904a;
            }
        }

        i(Class cls, dn.l lVar) {
            this.f33734q = cls;
            this.f33735r = lVar;
        }

        @Override // java.lang.Runnable
        public final void run() {
            String extensionTypeName = qg.h.d(this.f33734q);
            if (a.this.f33693c.containsKey(extensionTypeName)) {
                dn.l lVar = this.f33735r;
                if (lVar != null) {
                    a.this.B(new RunnableC0785a(lVar));
                    return;
                }
                return;
            }
            a.this.D(this.f33734q);
            qg.g gVar = new qg.g(this.f33734q, new b());
            ConcurrentHashMap concurrentHashMap = a.this.f33693c;
            kotlin.jvm.internal.t.f(extensionTypeName, "extensionTypeName");
            concurrentHashMap.put(extensionTypeName, gVar);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class j implements Callable {

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ qg.m f33743b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ String f33744c;

        /* renamed from: d, reason: collision with root package name */
        final /* synthetic */ int f33745d;

        /* renamed from: e, reason: collision with root package name */
        final /* synthetic */ Map f33746e;

        j(qg.m mVar, String str, int i10, Map map) {
            this.f33743b = mVar;
            this.f33744c = str;
            this.f33745d = i10;
            this.f33746e = map;
        }

        public final void a() {
            qg.l K = a.this.K(this.f33743b, this.f33744c);
            if (K == null) {
                t.f("MobileCore", "EventHub", "Resolve pending " + this.f33743b + " shared state for extension \"" + this.f33744c + "\" and version " + this.f33745d + " failed - SharedStateManager is null", new Object[0]);
                return;
            }
            if (!K.g(this.f33745d, this.f33746e)) {
                t.f("MobileCore", "EventHub", "Resolve pending " + this.f33743b + " shared state for extension \"" + this.f33744c + "\" and version " + this.f33745d + " failed - SharedStateManager failed", new Object[0]);
                return;
            }
            StringBuilder sb2 = new StringBuilder();
            sb2.append("Resolved pending ");
            sb2.append(this.f33743b);
            sb2.append(" shared state for \"");
            sb2.append(this.f33744c);
            sb2.append("\" and version ");
            sb2.append(this.f33745d);
            sb2.append(" with data ");
            Map map = this.f33746e;
            sb2.append(map != null ? com.adobe.marketing.mobile.internal.util.e.f(map) : null);
            t.a("MobileCore", "EventHub", sb2.toString(), new Object[0]);
            a.this.A(this.f33743b, this.f33744c);
        }

        @Override // java.util.concurrent.Callable
        public /* bridge */ /* synthetic */ Object call() {
            a();
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class k extends v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        public static final k f33747p = new k();

        k() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final ScheduledExecutorService invoke() {
            return Executors.newSingleThreadScheduledExecutor();
        }
    }

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

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ dn.a f33749q;

        l(dn.a aVar) {
            this.f33749q = aVar;
        }

        @Override // java.lang.Runnable
        public final void run() {
            if (a.this.f33699i) {
                t.a("MobileCore", "EventHub", "Dropping start call as it was already received", new Object[0]);
                return;
            }
            a.this.f33699i = true;
            a.this.f33700j = this.f33749q;
            a.this.V();
        }
    }

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

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ dn.a f33750p;

        m(dn.a aVar) {
            this.f33750p = aVar;
        }

        @Override // java.lang.Runnable
        public final void run() {
            this.f33750p.invoke();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class n implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ dn.l f33751p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ a f33752q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ qg.c f33753r;

        n(dn.l lVar, a aVar, qg.c cVar) {
            this.f33751p = lVar;
            this.f33752q = aVar;
            this.f33753r = cVar;
        }

        @Override // java.lang.Runnable
        public final void run() {
            dn.l lVar = this.f33751p;
            if (lVar != null) {
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class o implements Callable {
        o() {
        }

        @Override // java.util.concurrent.Callable
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final WrapperType call() {
            return a.this.f33705o;
        }
    }

    public a() {
        rm.o a10;
        rm.o a11;
        a10 = q.a(k.f33747p);
        this.f33691a = a10;
        a11 = q.a(f.f33725p);
        this.f33692b = a11;
        this.f33693c = new ConcurrentHashMap();
        this.f33694d = new ConcurrentLinkedQueue();
        this.f33695e = new ConcurrentLinkedQueue();
        this.f33696f = new AtomicInteger(0);
        this.f33697g = new ConcurrentHashMap();
        this.f33698h = new LinkedHashSet();
        e eVar = new e();
        this.f33702l = eVar;
        this.f33703m = new ch.h("EventHub", eVar);
        Q(this, EventHubPlaceholderExtension.class, null, 2, null);
        this.f33705o = WrapperType.NONE;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void A(qg.m mVar, String str) {
        Map e10;
        String str2 = mVar == qg.m.STANDARD ? "Shared state change" : "Shared state change (XDM)";
        e10 = p0.e(c0.a("stateowner", str));
        Event event = new Event.Builder(str2, "com.adobe.eventType.hub", "com.adobe.eventSource.sharedState").d(e10).a();
        kotlin.jvm.internal.t.f(event, "event");
        z(event);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void B(Runnable runnable) {
        I().submit(new g(runnable));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void C(Class cls, qg.c cVar) {
        if (cVar != qg.c.None) {
            t.f("MobileCore", "EventHub", "Extension " + cls + " registration failed with error " + cVar, new Object[0]);
            X(this, cls, null, 2, null);
        } else {
            t.e("MobileCore", "EventHub", "Extension " + cls + " registered successfully", new Object[0]);
            T();
        }
        if (this.f33701k) {
            return;
        }
        this.f33698h.remove(cls);
        V();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void D(Class cls) {
        if (this.f33699i) {
            return;
        }
        this.f33698h.add(cls);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final ExecutorService F() {
        return (ExecutorService) this.f33692b.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Integer G(Event event) {
        if (event == null) {
            return null;
        }
        return (Integer) this.f33697g.get(event.x());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final qg.g H(String str) {
        Object obj;
        Set entrySet = this.f33693c.entrySet();
        kotlin.jvm.internal.t.f(entrySet, "registeredExtensions.entries");
        Iterator it = entrySet.iterator();
        while (true) {
            if (!it.hasNext()) {
                obj = null;
                break;
            }
            obj = it.next();
            String y10 = ((qg.g) ((Map.Entry) obj).getValue()).y();
            if (y10 != null ? y.z(y10, str, true) : false) {
                break;
            }
        }
        Map.Entry entry = (Map.Entry) obj;
        if (entry != null) {
            return (qg.g) entry.getValue();
        }
        return null;
    }

    private final ScheduledExecutorService I() {
        return (ScheduledExecutorService) this.f33691a.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final qg.l K(qg.m mVar, String str) {
        qg.l x10;
        qg.g H = H(str);
        if (H == null || (x10 = H.x(mVar)) == null) {
            return null;
        }
        return x10;
    }

    public static /* synthetic */ void Q(a aVar, Class cls, dn.l lVar, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            lVar = null;
        }
        aVar.P(cls, lVar);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void R(qg.m mVar, String str, Map map, int i10) {
        Map map2;
        try {
            map2 = ch.d.f(map);
        } catch (Exception e10) {
            t.f("MobileCore", "EventHub", "Resolving pending " + mVar + " shared state for extension \"" + str + "\" and version " + i10 + " with null - Clone failed with exception " + e10, new Object[0]);
            map2 = null;
        }
        F().submit(new j(mVar, str, i10, map2)).get();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final int S(qg.l lVar, Event event) {
        if (event == null) {
            if (lVar.a()) {
                return 0;
            }
            return this.f33696f.incrementAndGet();
        }
        Integer G = G(event);
        if (G != null) {
            return G.intValue();
        }
        return 0;
    }

    private final void T() {
        Map l10;
        Map l11;
        Map m10;
        if (this.f33701k) {
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            Collection<qg.g> values = this.f33693c.values();
            kotlin.jvm.internal.t.f(values, "registeredExtensions.values");
            for (qg.g gVar : values) {
                String y10 = gVar.y();
                if (y10 != null && (!kotlin.jvm.internal.t.b(y10, "com.adobe.module.eventhub"))) {
                    m10 = q0.m(c0.a("friendlyName", gVar.u()), c0.a("version", gVar.A()));
                    Map w10 = gVar.w();
                    if (w10 != null) {
                        m10.put("metadata", w10);
                    }
                    linkedHashMap.put(y10, m10);
                }
            }
            l10 = q0.l(c0.a("type", this.f33705o.getWrapperTag()), c0.a("friendlyName", this.f33705o.getFriendlyName()));
            l11 = q0.l(c0.a("version", "2.2.2"), c0.a("wrapper", l10), c0.a("extensions", linkedHashMap));
            x(qg.m.STANDARD, "com.adobe.module.eventhub", ch.d.f(l11), null);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void V() {
        boolean z10;
        if (this.f33701k || !(z10 = this.f33699i)) {
            return;
        }
        if (!z10 || this.f33698h.size() == 0) {
            t.e("MobileCore", "EventHub", "EventHub started. Will begin processing events", new Object[0]);
            this.f33701k = true;
            this.f33703m.w();
            T();
            dn.a aVar = this.f33700j;
            if (aVar != null) {
                B(new m(aVar));
            }
            this.f33700j = null;
        }
    }

    private final void W(Class cls, dn.l lVar) {
        qg.c cVar;
        qg.g gVar = (qg.g) this.f33693c.remove(qg.h.d(cls));
        if (gVar != null) {
            gVar.B();
            T();
            t.e("MobileCore", "EventHub", "Extension " + cls + " unregistered successfully", new Object[0]);
            cVar = qg.c.None;
        } else {
            t.f("MobileCore", "EventHub", "Extension " + cls + " unregistration failed as extension was not registered", new Object[0]);
            cVar = qg.c.ExtensionNotRegistered;
        }
        B(new n(lVar, this, cVar));
    }

    static /* synthetic */ void X(a aVar, Class cls, dn.l lVar, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            lVar = null;
        }
        aVar.W(cls, lVar);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean x(qg.m mVar, String str, Map map, Event event) {
        qg.l K = K(mVar, str);
        if (K == null) {
            StringBuilder sb2 = new StringBuilder();
            sb2.append("Create ");
            sb2.append(mVar);
            sb2.append(" shared state for extension \"");
            sb2.append(str);
            sb2.append("\" for event ");
            sb2.append(event != null ? event.x() : null);
            sb2.append(" failed - SharedStateManager is null");
            t.f("MobileCore", "EventHub", sb2.toString(), new Object[0]);
            return false;
        }
        int S = S(K, event);
        boolean f10 = K.f(S, map);
        if (f10) {
            StringBuilder sb3 = new StringBuilder();
            sb3.append("Created ");
            sb3.append(mVar);
            sb3.append(" shared state for extension \"");
            sb3.append(str);
            sb3.append("\" with version ");
            sb3.append(S);
            sb3.append(" and data ");
            sb3.append(map != null ? com.adobe.marketing.mobile.internal.util.e.f(map) : null);
            t.a("MobileCore", "EventHub", sb3.toString(), new Object[0]);
            A(mVar, str);
        } else {
            StringBuilder sb4 = new StringBuilder();
            sb4.append("Create ");
            sb4.append(mVar);
            sb4.append(" shared state for extension \"");
            sb4.append(str);
            sb4.append("\" for event ");
            sb4.append(event != null ? event.x() : null);
            sb4.append(" failed - SharedStateManager failed");
            t.f("MobileCore", "EventHub", sb4.toString(), new Object[0]);
        }
        return f10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void z(Event event) {
        int incrementAndGet = this.f33696f.incrementAndGet();
        ConcurrentHashMap concurrentHashMap = this.f33697g;
        String x10 = event.x();
        kotlin.jvm.internal.t.f(x10, "event.uniqueIdentifier");
        concurrentHashMap.put(x10, Integer.valueOf(incrementAndGet));
        if (!this.f33703m.n(event)) {
            t.f("MobileCore", "EventHub", "Failed to dispatch event #" + incrementAndGet + " - (" + event + ')', new Object[0]);
        }
        if (t.c().compareTo(LoggingMode.DEBUG) >= 0) {
            t.a("MobileCore", "EventHub", "Dispatching Event #" + incrementAndGet + " - (" + event + ')', new Object[0]);
        }
    }

    public final rg.c E() {
        return this.f33704n;
    }

    public final SharedStateResult J(qg.m sharedStateType, String extensionName, Event event, boolean z10, SharedStateResolution resolution) {
        kotlin.jvm.internal.t.g(sharedStateType, "sharedStateType");
        kotlin.jvm.internal.t.g(extensionName, "extensionName");
        kotlin.jvm.internal.t.g(resolution, "resolution");
        return (SharedStateResult) F().submit(new h(extensionName, sharedStateType, event, resolution, z10)).get();
    }

    public final WrapperType L() {
        Object obj = F().submit(new o()).get();
        kotlin.jvm.internal.t.f(obj, "eventHubExecutor.submit(…    }\n            ).get()");
        return (WrapperType) obj;
    }

    public final void M() {
        rg.a aVar;
        if (this.f33704n != null) {
            t.f("MobileCore", "EventHub", "Event history is already initialized", new Object[0]);
            return;
        }
        try {
            aVar = new rg.a();
        } catch (Exception e10) {
            t.f("MobileCore", "EventHub", "Event history initialization failed with exception " + e10.getMessage(), new Object[0]);
            aVar = null;
        }
        this.f33704n = aVar;
    }

    public final void N(qg.f eventPreprocessor) {
        kotlin.jvm.internal.t.g(eventPreprocessor, "eventPreprocessor");
        if (this.f33695e.contains(eventPreprocessor)) {
            return;
        }
        this.f33695e.add(eventPreprocessor);
    }

    public final void O(Class cls) {
        Q(this, cls, null, 2, null);
    }

    public final void P(Class extensionClass, dn.l lVar) {
        kotlin.jvm.internal.t.g(extensionClass, "extensionClass");
        F().submit(new i(extensionClass, lVar));
    }

    public final void U(dn.a aVar) {
        F().submit(new l(aVar));
    }

    public final SharedStateResolver v(qg.m sharedStateType, String extensionName, Event event) {
        kotlin.jvm.internal.t.g(sharedStateType, "sharedStateType");
        kotlin.jvm.internal.t.g(extensionName, "extensionName");
        return (SharedStateResolver) F().submit(new b(sharedStateType, extensionName, event)).get();
    }

    public final boolean w(qg.m sharedStateType, String extensionName, Map map, Event event) {
        Map map2;
        kotlin.jvm.internal.t.g(sharedStateType, "sharedStateType");
        kotlin.jvm.internal.t.g(extensionName, "extensionName");
        try {
            map2 = ch.d.f(map);
        } catch (Exception e10) {
            StringBuilder sb2 = new StringBuilder();
            sb2.append("Creating ");
            sb2.append(sharedStateType);
            sb2.append(" shared state for extension ");
            sb2.append(extensionName);
            sb2.append(" at event ");
            sb2.append(event != null ? event.x() : null);
            sb2.append(" with null - Cloning state failed with exception ");
            sb2.append(e10);
            t.f("MobileCore", "EventHub", sb2.toString(), new Object[0]);
            map2 = null;
        }
        Object obj = F().submit(new c(sharedStateType, extensionName, map2, event)).get();
        kotlin.jvm.internal.t.f(obj, "eventHubExecutor.submit(callable).get()");
        return ((Boolean) obj).booleanValue();
    }

    public final void y(Event event) {
        kotlin.jvm.internal.t.g(event, "event");
        F().submit(new d(event));
    }
}
