package com.google.android.gms.internal.measurement;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.Callable;

/* JADX INFO: loaded from: classes.dex */
public final class D {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final C2.a f9577a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public C2.a f9578b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final A1.y f9579c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final C0700t f9580d;

    public D() {
        C2.a aVar = new C2.a(12);
        this.f9577a = aVar;
        this.f9578b = ((C2.a) aVar.f1157r).M();
        this.f9579c = new A1.y(29);
        this.f9580d = new C0700t(2);
        final int i = 0;
        Callable callable = new Callable(this) { // from class: com.google.android.gms.internal.measurement.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ D f9805b;

            {
                this.f9805b = this;
            }

            @Override // java.util.concurrent.Callable
            public final Object call() {
                switch (i) {
                    case n4.u0.f15495q /* 0 */:
                        return new H1(this.f9805b.f9580d);
                    default:
                        return new H1(this.f9805b.f9579c);
                }
            }
        };
        C0674n2 c0674n2 = (C0674n2) aVar.f1160u;
        ((HashMap) c0674n2.f9927a).put("internal.registerCallback", callable);
        final int i5 = 1;
        ((HashMap) c0674n2.f9927a).put("internal.eventLogger", new Callable(this) { // from class: com.google.android.gms.internal.measurement.a

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ D f9805b;

            {
                this.f9805b = this;
            }

            @Override // java.util.concurrent.Callable
            public final Object call() {
                switch (i5) {
                    case n4.u0.f15495q /* 0 */:
                        return new H1(this.f9805b.f9580d);
                    default:
                        return new H1(this.f9805b.f9579c);
                }
            }
        });
    }

    public final void a(C0688q1 c0688q1) throws N {
        AbstractC0641h abstractC0641h;
        try {
            C2.a aVar = this.f9577a;
            this.f9578b = ((C2.a) aVar.f1157r).M();
            if (aVar.O(this.f9578b, (C0692r1[]) c0688q1.o().toArray(new C0692r1[0])) instanceof C0631f) {
                throw new IllegalStateException("Program loading failed");
            }
            for (C0683p1 c0683p1 : c0688q1.n().p()) {
                InterfaceC0639g2 interfaceC0639g2O = c0683p1.o();
                String strN = c0683p1.n();
                Iterator it = interfaceC0639g2O.iterator();
                while (it.hasNext()) {
                    InterfaceC0671n interfaceC0671nO = aVar.O(this.f9578b, (C0692r1) it.next());
                    if (!(interfaceC0671nO instanceof C0656k)) {
                        throw new IllegalArgumentException("Invalid rule definition");
                    }
                    C2.a aVar2 = this.f9578b;
                    if (aVar2.V(strN)) {
                        InterfaceC0671n interfaceC0671nS = aVar2.S(strN);
                        if (!(interfaceC0671nS instanceof AbstractC0641h)) {
                            throw new IllegalStateException("Invalid function name: ".concat(String.valueOf(strN)));
                        }
                        abstractC0641h = (AbstractC0641h) interfaceC0671nS;
                    } else {
                        abstractC0641h = null;
                    }
                    if (abstractC0641h == null) {
                        throw new IllegalStateException("Rule function is undefined: ".concat(String.valueOf(strN)));
                    }
                    abstractC0641h.d(this.f9578b, Collections.singletonList(interfaceC0671nO));
                }
            }
        } catch (Throwable th) {
            throw new N(th);
        }
    }

    public final boolean b(C0611b c0611b) throws N {
        A1.y yVar = this.f9579c;
        try {
            yVar.f363r = c0611b;
            yVar.f364s = c0611b.clone();
            ((ArrayList) yVar.f365t).clear();
            ((C2.a) this.f9577a.f1159t).U("runtime.counter", new C0636g(Double.valueOf(0.0d)));
            this.f9580d.c(this.f9578b.M(), yVar);
            if (((C0611b) yVar.f364s).equals((C0611b) yVar.f363r)) {
                return !((ArrayList) yVar.f365t).isEmpty();
            }
            return true;
        } catch (Throwable th) {
            throw new N(th);
        }
    }
}
