package d3;

import android.util.Log;
import com.google.android.gms.internal.measurement.AbstractC0609a2;
import com.google.android.gms.internal.measurement.C0650i3;
import com.google.android.gms.internal.measurement.C0673n1;
import com.google.android.gms.internal.measurement.C0682p0;
import com.google.android.gms.internal.measurement.C0691r0;
import com.google.android.gms.internal.measurement.C0706u0;
import com.google.android.gms.internal.measurement.C0716w0;
import com.google.android.gms.internal.measurement.C0721x0;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/* JADX INFO: renamed from: d3.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0769b {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f11885b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Boolean f11886c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Boolean f11887d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Long f11888e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Long f11889f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final /* synthetic */ int f11890g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final /* synthetic */ C0772c f11891h;
    public final AbstractC0609a2 i;

    public C0769b(C0772c c0772c, String str, int i, AbstractC0609a2 abstractC0609a2, int i5) {
        this.f11890g = i5;
        this.f11891h = c0772c;
        this.f11884a = str;
        this.f11885b = i;
        this.i = abstractC0609a2;
    }

    /* JADX WARN: Removed duplicated region for block: B:38:0x0089  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x0107  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Boolean c(BigDecimal bigDecimal, C0706u0 c0706u0, double d8) {
        BigDecimal bigDecimal2;
        BigDecimal bigDecimal3;
        BigDecimal bigDecimal4;
        int i;
        P2.w.f(c0706u0);
        if (c0706u0.s()) {
            if (c0706u0.x() != 1 && (c0706u0.x() != 5 ? c0706u0.t() : c0706u0.w() && c0706u0.v())) {
                int iX = c0706u0.x();
                try {
                    if (c0706u0.x() == 5) {
                        if (C0773c0.I(c0706u0.q()) && C0773c0.I(c0706u0.p())) {
                            BigDecimal bigDecimal5 = new BigDecimal(c0706u0.q());
                            bigDecimal4 = new BigDecimal(c0706u0.p());
                            bigDecimal3 = bigDecimal5;
                            bigDecimal2 = null;
                            if (iX == 5 ? bigDecimal2 != null : bigDecimal3 != null) {
                                i = iX - 1;
                                if (i != 1) {
                                    if (i != 2) {
                                        if (i != 3) {
                                            if (i == 4 && bigDecimal3 != null) {
                                                return Boolean.valueOf(bigDecimal.compareTo(bigDecimal3) >= 0 && bigDecimal.compareTo(bigDecimal4) <= 0);
                                            }
                                        } else if (bigDecimal2 != null) {
                                            if (d8 != 0.0d) {
                                                return Boolean.valueOf(bigDecimal.compareTo(bigDecimal2.subtract(new BigDecimal(d8).multiply(new BigDecimal(2)))) > 0 && bigDecimal.compareTo(bigDecimal2.add(new BigDecimal(d8).multiply(new BigDecimal(2)))) < 0);
                                            }
                                            return Boolean.valueOf(bigDecimal.compareTo(bigDecimal2) == 0);
                                        }
                                    } else if (bigDecimal2 != null) {
                                        return Boolean.valueOf(bigDecimal.compareTo(bigDecimal2) > 0);
                                    }
                                } else if (bigDecimal2 != null) {
                                    return Boolean.valueOf(bigDecimal.compareTo(bigDecimal2) < 0);
                                }
                            }
                        }
                    } else if (C0773c0.I(c0706u0.o())) {
                        bigDecimal2 = new BigDecimal(c0706u0.o());
                        bigDecimal3 = null;
                        bigDecimal4 = null;
                        if (iX == 5) {
                            i = iX - 1;
                            if (i != 1) {
                            }
                        } else {
                            i = iX - 1;
                            if (i != 1) {
                            }
                        }
                    }
                } catch (NumberFormatException unused) {
                }
            }
        }
        return null;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    public static Boolean d(String str, C0721x0 c0721x0, Z z8) {
        List listQ;
        P2.w.f(c0721x0);
        if (str != null && c0721x0.u() && c0721x0.v() != 1 && (c0721x0.v() != 7 ? c0721x0.t() : c0721x0.n() != 0)) {
            int iV = c0721x0.v();
            boolean zR = c0721x0.r();
            String strP = (zR || iV == 2 || iV == 7) ? c0721x0.p() : c0721x0.p().toUpperCase(Locale.ENGLISH);
            if (c0721x0.n() == 0) {
                listQ = null;
            } else {
                listQ = c0721x0.q();
                if (!zR) {
                    ArrayList arrayList = new ArrayList(listQ.size());
                    Iterator it = listQ.iterator();
                    while (it.hasNext()) {
                        arrayList.add(((String) it.next()).toUpperCase(Locale.ENGLISH));
                    }
                    listQ = Collections.unmodifiableList(arrayList);
                }
            }
            String str2 = iV == 2 ? strP : null;
            if (iV != 7 ? strP != null : listQ != null && !listQ.isEmpty()) {
                if (!zR && iV != 2) {
                    str = str.toUpperCase(Locale.ENGLISH);
                }
                switch (iV - 1) {
                    case 1:
                        if (str2 != null) {
                            try {
                                return Boolean.valueOf(Pattern.compile(str2, true != zR ? 66 : 0).matcher(str).matches());
                            } catch (PatternSyntaxException unused) {
                                if (z8 != null) {
                                    z8.f11878y.c(str2, "Invalid regular expression in REGEXP audience filter. expression");
                                }
                            }
                        }
                        break;
                    case 2:
                        return Boolean.valueOf(str.startsWith(strP));
                    case 3:
                        return Boolean.valueOf(str.endsWith(strP));
                    case 4:
                        return Boolean.valueOf(str.contains(strP));
                    case 5:
                        return Boolean.valueOf(str.equals(strP));
                    case Z.g.STRING_SET_FIELD_NUMBER /* 6 */:
                        if (listQ != null) {
                            return Boolean.valueOf(listQ.contains(str));
                        }
                        break;
                }
            }
        }
        return null;
    }

    public static Boolean e(long j8, C0706u0 c0706u0) {
        try {
            return c(new BigDecimal(j8), c0706u0, 0.0d);
        } catch (NumberFormatException unused) {
            return null;
        }
    }

    public static Boolean f(Boolean bool, boolean z8) {
        if (bool == null) {
            return null;
        }
        return Boolean.valueOf(bool.booleanValue() != z8);
    }

    /* JADX WARN: Code restructure failed: missing block: B:103:0x0292, code lost:
    
        r16 = r3;
        r17 = r4;
     */
    /* JADX WARN: Code restructure failed: missing block: B:110:0x02b1, code lost:
    
        r16 = r3;
        r17 = r4;
     */
    /* JADX WARN: Removed duplicated region for block: B:56:0x0178  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean a(Long l8, Long l9, com.google.android.gms.internal.measurement.W0 w02, long j8, C0819s c0819s, boolean z8) {
        boolean z9;
        C0682p0 c0682p0;
        boolean z10;
        Boolean bool;
        Boolean boolC;
        Boolean boolC2;
        C0650i3.a();
        C0772c c0772c = this.f11891h;
        C0817r0 c0817r0 = (C0817r0) c0772c.f5146q;
        C0784g c0784g = c0817r0.f12148w;
        H h8 = I.f11497F0;
        String str = this.f11884a;
        boolean zR = c0784g.R(str, h8);
        C0682p0 c0682p02 = (C0682p0) this.i;
        long j9 = c0682p02.y() ? c0819s.f12159e : j8;
        Z z11 = c0817r0.f12150y;
        C0817r0.k(z11);
        boolean zIsLoggable = Log.isLoggable(z11.P(), 2);
        boolean z12 = false;
        X x8 = z11.D;
        int i = this.f11885b;
        T t6 = c0817r0.f12123C;
        if (zIsLoggable) {
            C0817r0.k(z11);
            x8.e("Evaluating filter. audience, filter, event", Integer.valueOf(i), c0682p02.A() ? Integer.valueOf(c0682p02.o()) : null, t6.d(c0682p02.s()));
            C0817r0.k(z11);
            C0773c0 c0773c0 = c0772c.f11473r.f11687w;
            Q1.L(c0773c0);
            StringBuilder sb = new StringBuilder();
            sb.append("\nevent_filter {\n");
            if (c0682p02.A()) {
                C0773c0.W(sb, 0, "filter_id", Integer.valueOf(c0682p02.o()));
            }
            C0773c0.W(sb, 0, "event_name", ((C0817r0) c0773c0.f5146q).f12123C.d(c0682p02.s()));
            String strT = C0773c0.T(c0682p02.w(), c0682p02.x(), c0682p02.y());
            if (!strT.isEmpty()) {
                C0773c0.W(sb, 0, "filter_type", strT);
            }
            if (c0682p02.z()) {
                C0773c0.X(sb, 1, "event_count_filter", c0682p02.r());
            }
            if (c0682p02.n() > 0) {
                sb.append("  filters {\n");
                Iterator it = c0682p02.t().iterator();
                while (it.hasNext()) {
                    c0773c0.Q(sb, 2, (C0691r0) it.next());
                }
            }
            C0773c0.R(1, sb);
            sb.append("}\n}\n");
            x8.c(sb.toString(), "Filter definition");
        }
        boolean zA = c0682p02.A();
        X x9 = z11.f11878y;
        if (!zA || c0682p02.o() > 256) {
            C0817r0.k(z11);
            x9.d("Invalid event filter ID. appId, id", Z.M(str), String.valueOf(c0682p02.A() ? Integer.valueOf(c0682p02.o()) : null));
            return false;
        }
        boolean z13 = c0682p02.w() || c0682p02.x() || c0682p02.y();
        if (z8 && !z13) {
            C0817r0.k(z11);
            x8.d("Event filter already evaluated true and it is not associated with an enhanced audience. audience ID, filter ID", Integer.valueOf(i), c0682p02.A() ? Integer.valueOf(c0682p02.o()) : null);
            return true;
        }
        String strT2 = w02.t();
        if (c0682p02.z()) {
            Boolean boolE = e(j9, c0682p02.r());
            if (boolE != null) {
                if (!boolE.booleanValue()) {
                    bool = Boolean.FALSE;
                    z9 = zR;
                    c0682p0 = c0682p02;
                    z10 = false;
                }
            }
            z9 = zR;
            c0682p0 = c0682p02;
            z10 = z12;
            bool = null;
        } else {
            HashSet hashSet = new HashSet();
            Iterator it2 = c0682p02.t().iterator();
            while (true) {
                if (!it2.hasNext()) {
                    q.e eVar = new q.e(0);
                    Iterator it3 = w02.u().iterator();
                    while (true) {
                        if (!it3.hasNext()) {
                            Iterator it4 = c0682p02.t().iterator();
                            while (true) {
                                if (!it4.hasNext()) {
                                    z9 = zR;
                                    c0682p0 = c0682p02;
                                    z10 = z12;
                                    bool = Boolean.TRUE;
                                    break;
                                }
                                C0691r0 c0691r0 = (C0691r0) it4.next();
                                boolean z14 = (c0691r0.t() && c0691r0.s()) ? true : z12;
                                String strQ = c0691r0.q();
                                if (strQ.isEmpty()) {
                                    C0817r0.k(z11);
                                    x9.c(t6.d(strT2), "Event has empty param name. event");
                                    break;
                                }
                                Object obj = eVar.get(strQ);
                                z10 = z12;
                                if (obj instanceof Long) {
                                    if (!c0691r0.u()) {
                                        C0817r0.k(z11);
                                        x9.d("No number filter for long param. event, param", t6.d(strT2), t6.e(strQ));
                                        break;
                                    }
                                    Boolean boolE2 = e(((Long) obj).longValue(), c0691r0.o());
                                    if (boolE2 == null) {
                                        break;
                                    }
                                    if (boolE2.booleanValue() == z14) {
                                        bool = Boolean.FALSE;
                                        break;
                                    }
                                    z12 = z10;
                                } else if (obj instanceof Double) {
                                    if (!c0691r0.u()) {
                                        C0817r0.k(z11);
                                        x9.d("No number filter for double param. event, param", t6.d(strT2), t6.e(strQ));
                                        break;
                                    }
                                    double dDoubleValue = ((Double) obj).doubleValue();
                                    try {
                                        boolC = c(new BigDecimal(dDoubleValue), c0691r0.o(), Math.ulp(dDoubleValue));
                                    } catch (NumberFormatException unused) {
                                        boolC = null;
                                    }
                                    if (boolC == null) {
                                        break;
                                    }
                                    if (boolC.booleanValue() == z14) {
                                        bool = Boolean.FALSE;
                                        break;
                                    }
                                    z12 = z10;
                                } else if (obj instanceof String) {
                                    if (!c0691r0.w()) {
                                        if (!c0691r0.u()) {
                                            z9 = zR;
                                            c0682p0 = c0682p02;
                                            C0817r0.k(z11);
                                            x9.d("No filter for String param. event, param", t6.d(strT2), t6.e(strQ));
                                            break;
                                        }
                                        String str2 = (String) obj;
                                        if (!C0773c0.I(str2)) {
                                            z9 = zR;
                                            c0682p0 = c0682p02;
                                            C0817r0.k(z11);
                                            x9.d("Invalid param value for number filter. event, param", t6.d(strT2), t6.e(strQ));
                                            break;
                                        }
                                        C0706u0 c0706u0O = c0691r0.o();
                                        if (C0773c0.I(str2)) {
                                            try {
                                                z9 = zR;
                                                c0682p0 = c0682p02;
                                                try {
                                                    boolC2 = c(new BigDecimal(str2), c0706u0O, 0.0d);
                                                } catch (NumberFormatException unused2) {
                                                    boolC2 = null;
                                                }
                                            } catch (NumberFormatException unused3) {
                                                z9 = zR;
                                                c0682p0 = c0682p02;
                                            }
                                        } else {
                                            z9 = zR;
                                            c0682p0 = c0682p02;
                                            boolC2 = null;
                                        }
                                    } else {
                                        C0721x0 c0721x0P = c0691r0.p();
                                        C0817r0.k(z11);
                                        boolC2 = d((String) obj, c0721x0P, z11);
                                        z9 = zR;
                                        c0682p0 = c0682p02;
                                    }
                                    if (boolC2 == null) {
                                        break;
                                    }
                                    if (boolC2.booleanValue() == z14) {
                                        bool = Boolean.FALSE;
                                        break;
                                    }
                                    z12 = z10;
                                    zR = z9;
                                    c0682p02 = c0682p0;
                                } else {
                                    z9 = zR;
                                    c0682p0 = c0682p02;
                                    if (obj == null) {
                                        C0817r0.k(z11);
                                        x8.d("Missing param for filter. event, param", t6.d(strT2), t6.e(strQ));
                                        bool = Boolean.FALSE;
                                    } else {
                                        C0817r0.k(z11);
                                        x9.d("Unknown param type. event, param", t6.d(strT2), t6.e(strQ));
                                    }
                                }
                            }
                        } else {
                            com.google.android.gms.internal.measurement.Z0 z02 = (com.google.android.gms.internal.measurement.Z0) it3.next();
                            if (hashSet.contains(z02.s())) {
                                if (!z02.H()) {
                                    if (!z02.F()) {
                                        if (!z02.J()) {
                                            C0817r0.k(z11);
                                            x9.d("Unknown value for param. event, param", t6.d(strT2), t6.e(z02.s()));
                                            break;
                                        }
                                        eVar.put(z02.s(), z02.t());
                                    } else {
                                        eVar.put(z02.s(), z02.F() ? Double.valueOf(z02.n()) : null);
                                    }
                                } else {
                                    eVar.put(z02.s(), z02.H() ? Long.valueOf(z02.q()) : null);
                                }
                            }
                        }
                    }
                } else {
                    C0691r0 c0691r02 = (C0691r0) it2.next();
                    if (c0691r02.q().isEmpty()) {
                        C0817r0.k(z11);
                        x9.c(t6.d(strT2), "null or empty param name in filter. event");
                        break;
                    }
                    hashSet.add(c0691r02.q());
                }
            }
            z9 = zR;
            c0682p0 = c0682p02;
            z10 = z12;
            bool = null;
        }
        C0817r0.k(z11);
        x8.c(bool == null ? "null" : bool, "Event filter result");
        if (bool == null) {
            return z10;
        }
        Boolean bool2 = Boolean.TRUE;
        this.f11886c = bool2;
        if (!bool.booleanValue()) {
            return true;
        }
        this.f11887d = bool2;
        if (!z13 || !w02.F()) {
            return true;
        }
        Long lValueOf = Long.valueOf(w02.q());
        if (c0682p0.x()) {
            if (z9 && c0682p0.z()) {
                lValueOf = l8;
            }
            this.f11889f = lValueOf;
            return true;
        }
        if (z9 && c0682p0.z()) {
            lValueOf = l9;
        }
        this.f11888e = lValueOf;
        return true;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    public boolean b(Long l8, Long l9, C0673n1 c0673n1, boolean z8) {
        C0650i3.a();
        C0817r0 c0817r0 = (C0817r0) this.f11891h.f5146q;
        boolean zR = c0817r0.f12148w.R(this.f11884a, I.f11493D0);
        C0716w0 c0716w0 = (C0716w0) this.i;
        boolean zS = c0716w0.s();
        boolean zT = c0716w0.t();
        boolean zU = c0716w0.u();
        Object[] objArr = zS || zT || zU;
        Boolean boolF = null;
        boolC = null;
        Boolean boolC = null;
        boolF = null;
        boolF = null;
        boolF = null;
        Boolean boolC2 = null;
        boolF = null;
        Z z9 = c0817r0.f12150y;
        if (z8 && objArr != true) {
            C0817r0.k(z9);
            z9.D.d("Property filter already evaluated true and it is not associated with an enhanced audience. audience ID, filter ID", Integer.valueOf(this.f11885b), c0716w0.v() ? Integer.valueOf(c0716w0.n()) : null);
            return true;
        }
        C0691r0 c0691r0O = c0716w0.o();
        boolean zS2 = c0691r0O.s();
        boolean zE = c0673n1.E();
        T t6 = c0817r0.f12123C;
        if (zE) {
            if (c0691r0O.u()) {
                boolF = f(e(c0673n1.p(), c0691r0O.o()), zS2);
            } else {
                C0817r0.k(z9);
                z9.f11878y.c(t6.f(c0673n1.s()), "No number filter for long property. property");
            }
        } else if (c0673n1.C()) {
            if (c0691r0O.u()) {
                double dN = c0673n1.n();
                try {
                    boolC = c(new BigDecimal(dN), c0691r0O.o(), Math.ulp(dN));
                } catch (NumberFormatException unused) {
                }
                boolF = f(boolC, zS2);
            } else {
                C0817r0.k(z9);
                z9.f11878y.c(t6.f(c0673n1.s()), "No number filter for double property. property");
            }
        } else if (!c0673n1.G()) {
            C0817r0.k(z9);
            z9.f11878y.c(t6.f(c0673n1.s()), "User property has no value, property");
        } else if (c0691r0O.w()) {
            String strT = c0673n1.t();
            C0721x0 c0721x0P = c0691r0O.p();
            C0817r0.k(z9);
            boolF = f(d(strT, c0721x0P, z9), zS2);
        } else if (!c0691r0O.u()) {
            C0817r0.k(z9);
            z9.f11878y.c(t6.f(c0673n1.s()), "No string or number filter defined. property");
        } else if (C0773c0.I(c0673n1.t())) {
            String strT2 = c0673n1.t();
            C0706u0 c0706u0O = c0691r0O.o();
            if (C0773c0.I(strT2)) {
                try {
                    boolC2 = c(new BigDecimal(strT2), c0706u0O, 0.0d);
                } catch (NumberFormatException unused2) {
                }
            }
            boolF = f(boolC2, zS2);
        } else {
            C0817r0.k(z9);
            z9.f11878y.d("Invalid user property value for Numeric number filter. property, value", t6.f(c0673n1.s()), c0673n1.t());
        }
        C0817r0.k(z9);
        z9.D.c(boolF == null ? "null" : boolF, "Property filter result");
        if (boolF == null) {
            return false;
        }
        this.f11886c = Boolean.TRUE;
        if (!zU || boolF.booleanValue()) {
            if (!z8 || c0716w0.s()) {
                this.f11887d = boolF;
            }
            if (boolF.booleanValue() && objArr != false && c0673n1.F()) {
                long jQ = c0673n1.q();
                if (l8 != null) {
                    jQ = l8.longValue();
                }
                if (zR && c0716w0.s() && !c0716w0.t() && l9 != null) {
                    jQ = l9.longValue();
                }
                if (c0716w0.t()) {
                    this.f11889f = Long.valueOf(jQ);
                } else {
                    this.f11888e = Long.valueOf(jQ);
                }
            }
        }
        return true;
    }
}
