package com.google.firebase.firestore.remote;

import com.google.firebase.Timestamp;
import com.google.firebase.firestore.AggregateField;
import com.google.firebase.firestore.core.Bound;
import com.google.firebase.firestore.core.CompositeFilter;
import com.google.firebase.firestore.core.FieldFilter;
import com.google.firebase.firestore.core.Filter;
import com.google.firebase.firestore.core.OrderBy;
import com.google.firebase.firestore.core.Query;
import com.google.firebase.firestore.core.Target;
import com.google.firebase.firestore.local.QueryPurpose;
import com.google.firebase.firestore.local.TargetData;
import com.google.firebase.firestore.model.DatabaseId;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.MutableDocument;
import com.google.firebase.firestore.model.ObjectValue;
import com.google.firebase.firestore.model.ResourcePath;
import com.google.firebase.firestore.model.SnapshotVersion;
import com.google.firebase.firestore.model.Values;
import com.google.firebase.firestore.model.mutation.ArrayTransformOperation;
import com.google.firebase.firestore.model.mutation.DeleteMutation;
import com.google.firebase.firestore.model.mutation.FieldMask;
import com.google.firebase.firestore.model.mutation.FieldTransform;
import com.google.firebase.firestore.model.mutation.Mutation;
import com.google.firebase.firestore.model.mutation.MutationResult;
import com.google.firebase.firestore.model.mutation.NumericIncrementTransformOperation;
import com.google.firebase.firestore.model.mutation.PatchMutation;
import com.google.firebase.firestore.model.mutation.Precondition;
import com.google.firebase.firestore.model.mutation.ServerTimestampOperation;
import com.google.firebase.firestore.model.mutation.SetMutation;
import com.google.firebase.firestore.model.mutation.TransformOperation;
import com.google.firebase.firestore.model.mutation.VerifyMutation;
import com.google.firebase.firestore.remote.WatchChange;
import com.google.firebase.firestore.util.Assert;
import com.google.protobuf.M;
import com.google.protobuf.N;
import com.google.protobuf.R0;
import com.google.protobuf.W;
import e4.A0;
import e4.B;
import e4.B0;
import e4.C0;
import e4.C1970a0;
import e4.C1972b0;
import e4.C1973c;
import e4.C1974c0;
import e4.C1975d;
import e4.C1978e0;
import e4.C1982g0;
import e4.C1983h;
import e4.C1986i0;
import e4.C1988j0;
import e4.C1990k0;
import e4.C1992l0;
import e4.C1995n;
import e4.C1996n0;
import e4.C1997o;
import e4.C1998o0;
import e4.C1999p;
import e4.C2000p0;
import e4.C2003s;
import e4.C2004t;
import e4.C2005u;
import e4.C2006v;
import e4.C2007w;
import e4.C2008x;
import e4.C2010z;
import e4.EnumC1976d0;
import e4.EnumC1980f0;
import e4.EnumC1984h0;
import e4.EnumC1994m0;
import e4.EnumC2009y;
import e4.G;
import e4.I0;
import e4.J0;
import e4.K;
import e4.K0;
import e4.L;
import e4.P;
import e4.Q;
import e4.Q0;
import e4.S;
import e4.T;
import e4.U;
import e4.V;
import e4.X;
import e4.Y;
import e4.Z;
import e4.r;
import e4.s0;
import e4.t0;
import e4.u0;
import e4.v0;
import e4.w0;
import e4.x0;
import e4.y0;
import e4.z0;
import h4.C2233a;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import k4.r0;
import m1.AbstractC2464a;

/* JADX INFO: loaded from: classes3.dex */
public final class RemoteSerializer {
    private final DatabaseId databaseId;
    private final String databaseName;

    /* JADX INFO: renamed from: com.google.firebase.firestore.remote.RemoteSerializer$1, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$google$firebase$firestore$core$CompositeFilter$Operator;
        static final /* synthetic */ int[] $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator;
        static final /* synthetic */ int[] $SwitchMap$com$google$firebase$firestore$local$QueryPurpose;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$DocumentTransform$FieldTransform$TransformTypeCase;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$ListenResponse$ResponseTypeCase;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$Precondition$ConditionTypeCase;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$StructuredQuery$CompositeFilter$Operator;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$StructuredQuery$Direction;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$StructuredQuery$Filter$FilterTypeCase;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$StructuredQuery$UnaryFilter$Operator;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$TargetChange$TargetChangeType;
        static final /* synthetic */ int[] $SwitchMap$com$google$firestore$v1$Write$OperationCase;

        static {
            int[] iArr = new int[AbstractC2464a.d(6).length];
            $SwitchMap$com$google$firestore$v1$ListenResponse$ResponseTypeCase = iArr;
            try {
                iArr[0] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$ListenResponse$ResponseTypeCase[1] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$ListenResponse$ResponseTypeCase[2] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$ListenResponse$ResponseTypeCase[3] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$ListenResponse$ResponseTypeCase[4] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$ListenResponse$ResponseTypeCase[5] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            int[] iArr2 = new int[B0.values().length];
            $SwitchMap$com$google$firestore$v1$TargetChange$TargetChangeType = iArr2;
            try {
                iArr2[0] = 1;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$TargetChange$TargetChangeType[1] = 2;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$TargetChange$TargetChangeType[2] = 3;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$TargetChange$TargetChangeType[3] = 4;
            } catch (NoSuchFieldError unused10) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$TargetChange$TargetChangeType[4] = 5;
            } catch (NoSuchFieldError unused11) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$TargetChange$TargetChangeType[5] = 6;
            } catch (NoSuchFieldError unused12) {
            }
            int[] iArr3 = new int[EnumC1980f0.values().length];
            $SwitchMap$com$google$firestore$v1$StructuredQuery$Direction = iArr3;
            try {
                iArr3[1] = 1;
            } catch (NoSuchFieldError unused13) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$Direction[2] = 2;
            } catch (NoSuchFieldError unused14) {
            }
            int[] iArr4 = new int[EnumC1984h0.values().length];
            $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator = iArr4;
            try {
                iArr4[1] = 1;
            } catch (NoSuchFieldError unused15) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[2] = 2;
            } catch (NoSuchFieldError unused16) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[5] = 3;
            } catch (NoSuchFieldError unused17) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[6] = 4;
            } catch (NoSuchFieldError unused18) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[4] = 5;
            } catch (NoSuchFieldError unused19) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[3] = 6;
            } catch (NoSuchFieldError unused20) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[7] = 7;
            } catch (NoSuchFieldError unused21) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[8] = 8;
            } catch (NoSuchFieldError unused22) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[9] = 9;
            } catch (NoSuchFieldError unused23) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[10] = 10;
            } catch (NoSuchFieldError unused24) {
            }
            int[] iArr5 = new int[FieldFilter.Operator.values().length];
            $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator = iArr5;
            try {
                iArr5[FieldFilter.Operator.LESS_THAN.ordinal()] = 1;
            } catch (NoSuchFieldError unused25) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.LESS_THAN_OR_EQUAL.ordinal()] = 2;
            } catch (NoSuchFieldError unused26) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.EQUAL.ordinal()] = 3;
            } catch (NoSuchFieldError unused27) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.NOT_EQUAL.ordinal()] = 4;
            } catch (NoSuchFieldError unused28) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.GREATER_THAN.ordinal()] = 5;
            } catch (NoSuchFieldError unused29) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.GREATER_THAN_OR_EQUAL.ordinal()] = 6;
            } catch (NoSuchFieldError unused30) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.ARRAY_CONTAINS.ordinal()] = 7;
            } catch (NoSuchFieldError unused31) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.IN.ordinal()] = 8;
            } catch (NoSuchFieldError unused32) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.ARRAY_CONTAINS_ANY.ordinal()] = 9;
            } catch (NoSuchFieldError unused33) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[FieldFilter.Operator.NOT_IN.ordinal()] = 10;
            } catch (NoSuchFieldError unused34) {
            }
            int[] iArr6 = new int[s0.values().length];
            $SwitchMap$com$google$firestore$v1$StructuredQuery$UnaryFilter$Operator = iArr6;
            try {
                iArr6[1] = 1;
            } catch (NoSuchFieldError unused35) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$UnaryFilter$Operator[2] = 2;
            } catch (NoSuchFieldError unused36) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$UnaryFilter$Operator[3] = 3;
            } catch (NoSuchFieldError unused37) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$UnaryFilter$Operator[4] = 4;
            } catch (NoSuchFieldError unused38) {
            }
            int[] iArr7 = new int[EnumC1994m0.values().length];
            $SwitchMap$com$google$firestore$v1$StructuredQuery$Filter$FilterTypeCase = iArr7;
            try {
                iArr7[0] = 1;
            } catch (NoSuchFieldError unused39) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$Filter$FilterTypeCase[1] = 2;
            } catch (NoSuchFieldError unused40) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$Filter$FilterTypeCase[2] = 3;
            } catch (NoSuchFieldError unused41) {
            }
            int[] iArr8 = new int[EnumC1976d0.values().length];
            $SwitchMap$com$google$firestore$v1$StructuredQuery$CompositeFilter$Operator = iArr8;
            try {
                iArr8[1] = 1;
            } catch (NoSuchFieldError unused42) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$StructuredQuery$CompositeFilter$Operator[2] = 2;
            } catch (NoSuchFieldError unused43) {
            }
            int[] iArr9 = new int[CompositeFilter.Operator.values().length];
            $SwitchMap$com$google$firebase$firestore$core$CompositeFilter$Operator = iArr9;
            try {
                iArr9[CompositeFilter.Operator.AND.ordinal()] = 1;
            } catch (NoSuchFieldError unused44) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$core$CompositeFilter$Operator[CompositeFilter.Operator.OR.ordinal()] = 2;
            } catch (NoSuchFieldError unused45) {
            }
            int[] iArr10 = new int[QueryPurpose.values().length];
            $SwitchMap$com$google$firebase$firestore$local$QueryPurpose = iArr10;
            try {
                iArr10[QueryPurpose.LISTEN.ordinal()] = 1;
            } catch (NoSuchFieldError unused46) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$local$QueryPurpose[QueryPurpose.EXISTENCE_FILTER_MISMATCH.ordinal()] = 2;
            } catch (NoSuchFieldError unused47) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$local$QueryPurpose[QueryPurpose.EXISTENCE_FILTER_MISMATCH_BLOOM.ordinal()] = 3;
            } catch (NoSuchFieldError unused48) {
            }
            try {
                $SwitchMap$com$google$firebase$firestore$local$QueryPurpose[QueryPurpose.LIMBO_RESOLUTION.ordinal()] = 4;
            } catch (NoSuchFieldError unused49) {
            }
            int[] iArr11 = new int[AbstractC2464a.d(7).length];
            $SwitchMap$com$google$firestore$v1$DocumentTransform$FieldTransform$TransformTypeCase = iArr11;
            try {
                iArr11[0] = 1;
            } catch (NoSuchFieldError unused50) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$DocumentTransform$FieldTransform$TransformTypeCase[4] = 2;
            } catch (NoSuchFieldError unused51) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$DocumentTransform$FieldTransform$TransformTypeCase[5] = 3;
            } catch (NoSuchFieldError unused52) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$DocumentTransform$FieldTransform$TransformTypeCase[1] = 4;
            } catch (NoSuchFieldError unused53) {
            }
            int[] iArr12 = new int[AbstractC2464a.d(3).length];
            $SwitchMap$com$google$firestore$v1$Precondition$ConditionTypeCase = iArr12;
            try {
                iArr12[1] = 1;
            } catch (NoSuchFieldError unused54) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$Precondition$ConditionTypeCase[0] = 2;
            } catch (NoSuchFieldError unused55) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$Precondition$ConditionTypeCase[2] = 3;
            } catch (NoSuchFieldError unused56) {
            }
            int[] iArr13 = new int[J0.values().length];
            $SwitchMap$com$google$firestore$v1$Write$OperationCase = iArr13;
            try {
                iArr13[0] = 1;
            } catch (NoSuchFieldError unused57) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$Write$OperationCase[1] = 2;
            } catch (NoSuchFieldError unused58) {
            }
            try {
                $SwitchMap$com$google$firestore$v1$Write$OperationCase[2] = 3;
            } catch (NoSuchFieldError unused59) {
            }
        }
    }

    public RemoteSerializer(DatabaseId databaseId) {
        this.databaseId = databaseId;
        this.databaseName = encodedDatabaseId(databaseId).canonicalString();
    }

    private FieldMask decodeDocumentMask(C2006v c2006v) {
        int i6 = c2006v.i();
        HashSet hashSet = new HashSet(i6);
        for (int i7 = 0; i7 < i6; i7++) {
            hashSet.add(FieldPath.fromServerFormat(c2006v.h(i7)));
        }
        return FieldMask.fromSet(hashSet);
    }

    private FieldFilter.Operator decodeFieldFilterOperator(EnumC1984h0 enumC1984h0) {
        switch (AnonymousClass1.$SwitchMap$com$google$firestore$v1$StructuredQuery$FieldFilter$Operator[enumC1984h0.ordinal()]) {
            case 1:
                return FieldFilter.Operator.LESS_THAN;
            case 2:
                return FieldFilter.Operator.LESS_THAN_OR_EQUAL;
            case 3:
                return FieldFilter.Operator.EQUAL;
            case 4:
                return FieldFilter.Operator.NOT_EQUAL;
            case 5:
                return FieldFilter.Operator.GREATER_THAN_OR_EQUAL;
            case 6:
                return FieldFilter.Operator.GREATER_THAN;
            case 7:
                return FieldFilter.Operator.ARRAY_CONTAINS;
            case 8:
                return FieldFilter.Operator.IN;
            case 9:
                return FieldFilter.Operator.ARRAY_CONTAINS_ANY;
            case 10:
                return FieldFilter.Operator.NOT_IN;
            default:
                throw Assert.fail("Unhandled FieldFilter.operator %d", enumC1984h0);
        }
    }

    private FieldTransform decodeFieldTransform(C2010z c2010z) {
        int iC = AbstractC2464a.c(c2010z.p());
        if (iC == 0) {
            Assert.hardAssert(c2010z.o() == EnumC2009y.REQUEST_TIME, "Unknown transform setToServerValue: %s", c2010z.o());
            return new FieldTransform(FieldPath.fromServerFormat(c2010z.l()), ServerTimestampOperation.getInstance());
        }
        if (iC == 1) {
            return new FieldTransform(FieldPath.fromServerFormat(c2010z.l()), new NumericIncrementTransformOperation(c2010z.m()));
        }
        if (iC == 4) {
            return new FieldTransform(FieldPath.fromServerFormat(c2010z.l()), new ArrayTransformOperation.Union(c2010z.k().a()));
        }
        if (iC == 5) {
            return new FieldTransform(FieldPath.fromServerFormat(c2010z.l()), new ArrayTransformOperation.Remove(c2010z.n().a()));
        }
        throw Assert.fail("Unknown FieldTransform proto: %s", c2010z);
    }

    private List<Filter> decodeFilters(C1996n0 c1996n0) {
        Filter filterDecodeFilter = decodeFilter(c1996n0);
        if (filterDecodeFilter instanceof CompositeFilter) {
            CompositeFilter compositeFilter = (CompositeFilter) filterDecodeFilter;
            if (compositeFilter.isFlatConjunction()) {
                return compositeFilter.getFilters();
            }
        }
        return Collections.singletonList(filterDecodeFilter);
    }

    private MutableDocument decodeFoundDocument(C1983h c1983h) {
        Assert.hardAssert(AbstractC2464a.a(c1983h.i(), 1), "Tried to deserialize a found document from a missing document.", new Object[0]);
        DocumentKey documentKeyDecodeKey = decodeKey(c1983h.g().getName());
        ObjectValue objectValueFromMap = ObjectValue.fromMap(c1983h.g().j());
        SnapshotVersion snapshotVersionDecodeVersion = decodeVersion(c1983h.g().k());
        Assert.hardAssert(true ^ snapshotVersionDecodeVersion.equals(SnapshotVersion.NONE), "Got a document response with no snapshot version", new Object[0]);
        return MutableDocument.newFoundDocument(documentKeyDecodeKey, snapshotVersionDecodeVersion, objectValueFromMap);
    }

    private MutableDocument decodeMissingDocument(C1983h c1983h) {
        Assert.hardAssert(AbstractC2464a.a(c1983h.i(), 2), "Tried to deserialize a missing document from a found document.", new Object[0]);
        DocumentKey documentKeyDecodeKey = decodeKey(c1983h.h());
        SnapshotVersion snapshotVersionDecodeVersion = decodeVersion(c1983h.getReadTime());
        Assert.hardAssert(!snapshotVersionDecodeVersion.equals(SnapshotVersion.NONE), "Got a no document response with no snapshot version", new Object[0]);
        return MutableDocument.newNoDocument(documentKeyDecodeKey, snapshotVersionDecodeVersion);
    }

    private OrderBy decodeOrderBy(C2000p0 c2000p0) {
        OrderBy.Direction direction;
        FieldPath fieldPathFromServerFormat = FieldPath.fromServerFormat(c2000p0.i().h());
        int iOrdinal = c2000p0.h().ordinal();
        if (iOrdinal == 1) {
            direction = OrderBy.Direction.ASCENDING;
        } else {
            if (iOrdinal != 2) {
                throw Assert.fail("Unrecognized direction %d", c2000p0.h());
            }
            direction = OrderBy.Direction.DESCENDING;
        }
        return OrderBy.getInstance(direction, fieldPathFromServerFormat);
    }

    private Precondition decodePrecondition(L l) {
        int iC = AbstractC2464a.c(l.h());
        if (iC == 0) {
            return Precondition.exists(l.j());
        }
        if (iC == 1) {
            return Precondition.updateTime(decodeVersion(l.k()));
        }
        if (iC == 2) {
            return Precondition.NONE;
        }
        throw Assert.fail("Unknown precondition", new Object[0]);
    }

    private ResourcePath decodeQueryPath(String str) {
        ResourcePath resourcePathDecodeResourceName = decodeResourceName(str);
        return resourcePathDecodeResourceName.length() == 4 ? ResourcePath.EMPTY : extractLocalPathFromResourceName(resourcePathDecodeResourceName);
    }

    private ResourcePath decodeResourceName(String str) {
        ResourcePath resourcePathFromString = ResourcePath.fromString(str);
        Assert.hardAssert(isValidResourceName(resourcePathFromString), "Tried to deserialize invalid key %s", resourcePathFromString);
        return resourcePathFromString;
    }

    private Filter decodeUnaryFilter(t0 t0Var) {
        FieldPath fieldPathFromServerFormat = FieldPath.fromServerFormat(t0Var.i().h());
        int iOrdinal = t0Var.j().ordinal();
        if (iOrdinal == 1) {
            return FieldFilter.create(fieldPathFromServerFormat, FieldFilter.Operator.EQUAL, Values.NAN_VALUE);
        }
        if (iOrdinal == 2) {
            return FieldFilter.create(fieldPathFromServerFormat, FieldFilter.Operator.EQUAL, Values.NULL_VALUE);
        }
        if (iOrdinal == 3) {
            return FieldFilter.create(fieldPathFromServerFormat, FieldFilter.Operator.NOT_EQUAL, Values.NAN_VALUE);
        }
        if (iOrdinal == 4) {
            return FieldFilter.create(fieldPathFromServerFormat, FieldFilter.Operator.NOT_EQUAL, Values.NULL_VALUE);
        }
        throw Assert.fail("Unrecognized UnaryFilter.operator %d", t0Var.j());
    }

    private C2006v encodeDocumentMask(FieldMask fieldMask) {
        C2005u c2005uJ = C2006v.j();
        Iterator<FieldPath> it = fieldMask.getMask().iterator();
        while (it.hasNext()) {
            c2005uJ.c(it.next().canonicalString());
        }
        return (C2006v) c2005uJ.m359build();
    }

    private EnumC1984h0 encodeFieldFilterOperator(FieldFilter.Operator operator) {
        switch (AnonymousClass1.$SwitchMap$com$google$firebase$firestore$core$FieldFilter$Operator[operator.ordinal()]) {
            case 1:
                return EnumC1984h0.LESS_THAN;
            case 2:
                return EnumC1984h0.LESS_THAN_OR_EQUAL;
            case 3:
                return EnumC1984h0.EQUAL;
            case 4:
                return EnumC1984h0.NOT_EQUAL;
            case 5:
                return EnumC1984h0.GREATER_THAN;
            case 6:
                return EnumC1984h0.GREATER_THAN_OR_EQUAL;
            case 7:
                return EnumC1984h0.ARRAY_CONTAINS;
            case 8:
                return EnumC1984h0.IN;
            case 9:
                return EnumC1984h0.ARRAY_CONTAINS_ANY;
            case 10:
                return EnumC1984h0.NOT_IN;
            default:
                throw Assert.fail("Unknown operator %d", operator);
        }
    }

    private C1990k0 encodeFieldPath(FieldPath fieldPath) {
        C1988j0 c1988j0I = C1990k0.i();
        c1988j0I.c(fieldPath.canonicalString());
        return (C1990k0) c1988j0I.m359build();
    }

    private C2010z encodeFieldTransform(FieldTransform fieldTransform) {
        TransformOperation operation = fieldTransform.getOperation();
        if (operation instanceof ServerTimestampOperation) {
            C2008x c2008xQ = C2010z.q();
            c2008xQ.d(fieldTransform.getFieldPath().canonicalString());
            c2008xQ.h();
            return (C2010z) c2008xQ.m359build();
        }
        if (operation instanceof ArrayTransformOperation.Union) {
            C2008x c2008xQ2 = C2010z.q();
            c2008xQ2.d(fieldTransform.getFieldPath().canonicalString());
            C1973c c1973cL = C1975d.l();
            c1973cL.c(((ArrayTransformOperation.Union) operation).getElements());
            c2008xQ2.c(c1973cL);
            return (C2010z) c2008xQ2.m359build();
        }
        if (operation instanceof ArrayTransformOperation.Remove) {
            C2008x c2008xQ3 = C2010z.q();
            c2008xQ3.d(fieldTransform.getFieldPath().canonicalString());
            C1973c c1973cL2 = C1975d.l();
            c1973cL2.c(((ArrayTransformOperation.Remove) operation).getElements());
            c2008xQ3.f(c1973cL2);
            return (C2010z) c2008xQ3.m359build();
        }
        if (!(operation instanceof NumericIncrementTransformOperation)) {
            throw Assert.fail("Unknown transform: %s", operation);
        }
        C2008x c2008xQ4 = C2010z.q();
        c2008xQ4.d(fieldTransform.getFieldPath().canonicalString());
        c2008xQ4.e(((NumericIncrementTransformOperation) operation).getOperand());
        return (C2010z) c2008xQ4.m359build();
    }

    private C1996n0 encodeFilters(List<Filter> list) {
        return encodeFilter(new CompositeFilter(list, CompositeFilter.Operator.AND));
    }

    private String encodeLabel(QueryPurpose queryPurpose) {
        int i6 = AnonymousClass1.$SwitchMap$com$google$firebase$firestore$local$QueryPurpose[queryPurpose.ordinal()];
        if (i6 == 1) {
            return null;
        }
        if (i6 == 2) {
            return "existence-filter-mismatch";
        }
        if (i6 == 3) {
            return "existence-filter-mismatch-bloom";
        }
        if (i6 == 4) {
            return "limbo-document";
        }
        throw Assert.fail("Unrecognized query purpose: %s", queryPurpose);
    }

    private C2000p0 encodeOrderBy(OrderBy orderBy) {
        C1998o0 c1998o0J = C2000p0.j();
        if (orderBy.getDirection().equals(OrderBy.Direction.ASCENDING)) {
            c1998o0J.c(EnumC1980f0.ASCENDING);
        } else {
            c1998o0J.c(EnumC1980f0.DESCENDING);
        }
        c1998o0J.d(encodeFieldPath(orderBy.getField()));
        return (C2000p0) c1998o0J.m359build();
    }

    private L encodePrecondition(Precondition precondition) {
        Assert.hardAssert(!precondition.isNone(), "Can't serialize an empty precondition", new Object[0]);
        K kL = L.l();
        if (precondition.getUpdateTime() != null) {
            kL.d(encodeVersion(precondition.getUpdateTime()));
            return (L) kL.m359build();
        }
        if (precondition.getExists() == null) {
            throw Assert.fail("Unknown Precondition", new Object[0]);
        }
        kL.c(precondition.getExists().booleanValue());
        return (L) kL.m359build();
    }

    private String encodeQueryPath(ResourcePath resourcePath) {
        return encodeResourceName(this.databaseId, resourcePath);
    }

    private String encodeResourceName(DatabaseId databaseId, ResourcePath resourcePath) {
        return encodedDatabaseId(databaseId).append("documents").append(resourcePath).canonicalString();
    }

    private static ResourcePath encodedDatabaseId(DatabaseId databaseId) {
        return ResourcePath.fromSegments(Arrays.asList("projects", databaseId.getProjectId(), "databases", databaseId.getDatabaseId()));
    }

    private static ResourcePath extractLocalPathFromResourceName(ResourcePath resourcePath) {
        Assert.hardAssert(resourcePath.length() > 4 && resourcePath.getSegment(4).equals("documents"), "Tried to deserialize invalid key %s", resourcePath);
        return resourcePath.popFirst(5);
    }

    private r0 fromStatus(C2233a c2233a) {
        return r0.c(c2233a.f()).g(c2233a.h());
    }

    private static boolean isValidResourceName(ResourcePath resourcePath) {
        return resourcePath.length() >= 4 && resourcePath.getSegment(0).equals("projects") && resourcePath.getSegment(2).equals("databases");
    }

    public String databaseName() {
        return this.databaseName;
    }

    public CompositeFilter decodeCompositeFilter(C1978e0 c1978e0) {
        ArrayList arrayList = new ArrayList();
        Iterator it = c1978e0.i().iterator();
        while (it.hasNext()) {
            arrayList.add(decodeFilter((C1996n0) it.next()));
        }
        return new CompositeFilter(arrayList, decodeCompositeFilterOperator(c1978e0.j()));
    }

    public CompositeFilter.Operator decodeCompositeFilterOperator(EnumC1976d0 enumC1976d0) {
        int i6 = AnonymousClass1.$SwitchMap$com$google$firestore$v1$StructuredQuery$CompositeFilter$Operator[enumC1976d0.ordinal()];
        if (i6 == 1) {
            return CompositeFilter.Operator.AND;
        }
        if (i6 == 2) {
            return CompositeFilter.Operator.OR;
        }
        throw Assert.fail("Only AND and OR composite filter types are supported.", new Object[0]);
    }

    public Target decodeDocumentsTarget(x0 x0Var) {
        int i6 = x0Var.i();
        Assert.hardAssert(i6 == 1, "DocumentsTarget contained other than 1 document %d", Integer.valueOf(i6));
        return Query.atPath(decodeQueryPath(x0Var.h())).toTarget();
    }

    public FieldFilter decodeFieldFilter(C1986i0 c1986i0) {
        return FieldFilter.create(FieldPath.fromServerFormat(c1986i0.j().h()), decodeFieldFilterOperator(c1986i0.k()), c1986i0.l());
    }

    public Filter decodeFilter(C1996n0 c1996n0) {
        int iOrdinal = c1996n0.l().ordinal();
        if (iOrdinal == 0) {
            return decodeCompositeFilter(c1996n0.i());
        }
        if (iOrdinal == 1) {
            return decodeFieldFilter(c1996n0.k());
        }
        if (iOrdinal == 2) {
            return decodeUnaryFilter(c1996n0.m());
        }
        throw Assert.fail("Unrecognized Filter.filterType %d", c1996n0.l());
    }

    public DocumentKey decodeKey(String str) {
        ResourcePath resourcePathDecodeResourceName = decodeResourceName(str);
        Assert.hardAssert(resourcePathDecodeResourceName.getSegment(1).equals(this.databaseId.getProjectId()), "Tried to deserialize key from different project.", new Object[0]);
        Assert.hardAssert(resourcePathDecodeResourceName.getSegment(3).equals(this.databaseId.getDatabaseId()), "Tried to deserialize key from different database.", new Object[0]);
        return DocumentKey.fromPath(extractLocalPathFromResourceName(resourcePathDecodeResourceName));
    }

    public MutableDocument decodeMaybeDocument(C1983h c1983h) {
        if (AbstractC2464a.a(c1983h.i(), 1)) {
            return decodeFoundDocument(c1983h);
        }
        if (AbstractC2464a.a(c1983h.i(), 2)) {
            return decodeMissingDocument(c1983h);
        }
        int i6 = c1983h.i();
        throw new IllegalArgumentException("Unknown result case: ".concat(i6 != 1 ? i6 != 2 ? i6 != 3 ? "null" : "RESULT_NOT_SET" : "MISSING" : "FOUND"));
    }

    public Mutation decodeMutation(K0 k02) {
        Precondition preconditionDecodePrecondition = k02.t() ? decodePrecondition(k02.l()) : Precondition.NONE;
        ArrayList arrayList = new ArrayList();
        Iterator it = k02.r().iterator();
        while (it.hasNext()) {
            arrayList.add(decodeFieldTransform((C2010z) it.next()));
        }
        int iOrdinal = k02.n().ordinal();
        if (iOrdinal == 0) {
            return k02.w() ? new PatchMutation(decodeKey(k02.p().getName()), ObjectValue.fromMap(k02.p().j()), decodeDocumentMask(k02.q()), preconditionDecodePrecondition, arrayList) : new SetMutation(decodeKey(k02.p().getName()), ObjectValue.fromMap(k02.p().j()), preconditionDecodePrecondition, arrayList);
        }
        if (iOrdinal == 1) {
            return new DeleteMutation(decodeKey(k02.m()), preconditionDecodePrecondition);
        }
        if (iOrdinal == 2) {
            return new VerifyMutation(decodeKey(k02.s()), preconditionDecodePrecondition);
        }
        throw Assert.fail("Unknown mutation operation: %d", k02.n());
    }

    public MutationResult decodeMutationResult(Q0 q02, SnapshotVersion snapshotVersion) {
        SnapshotVersion snapshotVersionDecodeVersion = decodeVersion(q02.h());
        if (!SnapshotVersion.NONE.equals(snapshotVersionDecodeVersion)) {
            snapshotVersion = snapshotVersionDecodeVersion;
        }
        int iG = q02.g();
        ArrayList arrayList = new ArrayList(iG);
        for (int i6 = 0; i6 < iG; i6++) {
            arrayList.add(q02.f(i6));
        }
        return new MutationResult(snapshotVersion, arrayList);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v1, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r0v2 */
    /* JADX WARN: Type inference failed for: r0v8, types: [java.util.ArrayList] */
    /* JADX WARN: Type inference failed for: r8v0, types: [java.util.List] */
    public Target decodeQueryTarget(String str, u0 u0Var) {
        ResourcePath resourcePath;
        String strI;
        ?? arrayList;
        ResourcePath resourcePathDecodeQueryPath = decodeQueryPath(str);
        int iO = u0Var.o();
        if (iO <= 0) {
            resourcePath = resourcePathDecodeQueryPath;
            strI = null;
        } else {
            Assert.hardAssert(iO == 1, "StructuredQuery.from with more than one collection is not supported.", new Object[0]);
            C1972b0 c1972b0N = u0Var.n();
            if (c1972b0N.h()) {
                resourcePath = resourcePathDecodeQueryPath;
                strI = c1972b0N.i();
            } else {
                resourcePathDecodeQueryPath = resourcePathDecodeQueryPath.append(c1972b0N.i());
                resourcePath = resourcePathDecodeQueryPath;
                strI = null;
            }
        }
        List<Filter> listDecodeFilters = u0Var.x() ? decodeFilters(u0Var.t()) : Collections.EMPTY_LIST;
        int iR = u0Var.r();
        if (iR > 0) {
            arrayList = new ArrayList(iR);
            for (int i6 = 0; i6 < iR; i6++) {
                arrayList.add(decodeOrderBy(u0Var.q(i6)));
            }
        } else {
            arrayList = Collections.EMPTY_LIST;
        }
        return new Target(resourcePath, strI, listDecodeFilters, arrayList, u0Var.v() ? u0Var.p().h() : -1L, u0Var.w() ? new Bound(u0Var.s().a(), u0Var.s().h()) : null, u0Var.u() ? new Bound(u0Var.m().a(), !u0Var.m().h()) : null);
    }

    public Timestamp decodeTimestamp(R0 r02) {
        return new Timestamp(r02.j(), r02.i());
    }

    public SnapshotVersion decodeVersion(R0 r02) {
        return (r02.j() == 0 && r02.i() == 0) ? SnapshotVersion.NONE : new SnapshotVersion(decodeTimestamp(r02));
    }

    public SnapshotVersion decodeVersionFromListenResponse(G g6) {
        return g6.k() != 1 ? SnapshotVersion.NONE : g6.l().i() != 0 ? SnapshotVersion.NONE : decodeVersion(g6.l().getReadTime());
    }

    public WatchChange decodeWatchChange(G g6) {
        WatchChange.WatchTargetChangeType watchTargetChangeType;
        int iC = AbstractC2464a.c(g6.k());
        r0 r0VarFromStatus = null;
        if (iC == 0) {
            C0 c0L = g6.l();
            int iOrdinal = c0L.h().ordinal();
            if (iOrdinal == 0) {
                watchTargetChangeType = WatchChange.WatchTargetChangeType.NoChange;
            } else if (iOrdinal == 1) {
                watchTargetChangeType = WatchChange.WatchTargetChangeType.Added;
            } else if (iOrdinal == 2) {
                watchTargetChangeType = WatchChange.WatchTargetChangeType.Removed;
                r0VarFromStatus = fromStatus(c0L.f());
            } else if (iOrdinal == 3) {
                watchTargetChangeType = WatchChange.WatchTargetChangeType.Current;
            } else {
                if (iOrdinal != 4) {
                    throw new IllegalArgumentException("Unknown target change type");
                }
                watchTargetChangeType = WatchChange.WatchTargetChangeType.Reset;
            }
            return new WatchChange.WatchTargetChange(watchTargetChangeType, c0L.j(), c0L.getResumeToken(), r0VarFromStatus);
        }
        if (iC == 1) {
            C2003s c2003sG = g6.g();
            W wH = c2003sG.h();
            W wG = c2003sG.g();
            DocumentKey documentKeyDecodeKey = decodeKey(c2003sG.getDocument().getName());
            SnapshotVersion snapshotVersionDecodeVersion = decodeVersion(c2003sG.getDocument().k());
            Assert.hardAssert(!snapshotVersionDecodeVersion.equals(SnapshotVersion.NONE), "Got a document change without an update time", new Object[0]);
            MutableDocument mutableDocumentNewFoundDocument = MutableDocument.newFoundDocument(documentKeyDecodeKey, snapshotVersionDecodeVersion, ObjectValue.fromMap(c2003sG.getDocument().j()));
            return new WatchChange.DocumentChange(wH, wG, mutableDocumentNewFoundDocument.getKey(), mutableDocumentNewFoundDocument);
        }
        if (iC == 2) {
            C2004t c2004tH = g6.h();
            W wH2 = c2004tH.h();
            MutableDocument mutableDocumentNewNoDocument = MutableDocument.newNoDocument(decodeKey(c2004tH.g()), decodeVersion(c2004tH.getReadTime()));
            return new WatchChange.DocumentChange(Collections.EMPTY_LIST, wH2, mutableDocumentNewNoDocument.getKey(), mutableDocumentNewNoDocument);
        }
        if (iC == 3) {
            C2007w c2007wI = g6.i();
            return new WatchChange.DocumentChange(Collections.EMPTY_LIST, c2007wI.h(), decodeKey(c2007wI.g()), null);
        }
        if (iC != 4) {
            throw new IllegalArgumentException("Unknown change type set");
        }
        B bJ = g6.j();
        return new WatchChange.ExistenceFilterWatchChange(bJ.getTargetId(), new ExistenceFilter(bJ.f(), bJ.h()));
    }

    public C1996n0 encodeCompositeFilter(CompositeFilter compositeFilter) {
        ArrayList arrayList = new ArrayList(compositeFilter.getFilters().size());
        Iterator<Filter> it = compositeFilter.getFilters().iterator();
        while (it.hasNext()) {
            arrayList.add(encodeFilter(it.next()));
        }
        if (arrayList.size() == 1) {
            return (C1996n0) arrayList.get(0);
        }
        C1974c0 c1974c0K = C1978e0.k();
        c1974c0K.d(encodeCompositeFilterOperator(compositeFilter.getOperator()));
        c1974c0K.c(arrayList);
        C1992l0 c1992l0N = C1996n0.n();
        c1992l0N.c(c1974c0K);
        return (C1996n0) c1992l0N.m359build();
    }

    public EnumC1976d0 encodeCompositeFilterOperator(CompositeFilter.Operator operator) {
        int i6 = AnonymousClass1.$SwitchMap$com$google$firebase$firestore$core$CompositeFilter$Operator[operator.ordinal()];
        if (i6 == 1) {
            return EnumC1976d0.AND;
        }
        if (i6 == 2) {
            return EnumC1976d0.OR;
        }
        throw Assert.fail("Unrecognized composite filter type.", new Object[0]);
    }

    public r encodeDocument(DocumentKey documentKey, ObjectValue objectValue) {
        C1999p c1999pL = r.l();
        c1999pL.d(encodeKey(documentKey));
        c1999pL.c(objectValue.getFieldsMap());
        return (r) c1999pL.m359build();
    }

    public x0 encodeDocumentsTarget(Target target) {
        w0 w0VarJ = x0.j();
        w0VarJ.c(encodeQueryPath(target.getPath()));
        return (x0) w0VarJ.m359build();
    }

    public C1996n0 encodeFilter(Filter filter) {
        if (filter instanceof FieldFilter) {
            return encodeUnaryOrFieldFilter((FieldFilter) filter);
        }
        if (filter instanceof CompositeFilter) {
            return encodeCompositeFilter((CompositeFilter) filter);
        }
        throw Assert.fail("Unrecognized filter type %s", filter.toString());
    }

    public String encodeKey(DocumentKey documentKey) {
        return encodeResourceName(this.databaseId, documentKey.getPath());
    }

    public Map<String, String> encodeListenRequestLabels(TargetData targetData) {
        String strEncodeLabel = encodeLabel(targetData.getPurpose());
        if (strEncodeLabel == null) {
            return null;
        }
        HashMap map = new HashMap(1);
        map.put("goog-listen-tags", strEncodeLabel);
        return map;
    }

    public K0 encodeMutation(Mutation mutation) {
        I0 i0X = K0.x();
        if (mutation instanceof SetMutation) {
            i0X.f(encodeDocument(mutation.getKey(), ((SetMutation) mutation).getValue()));
        } else if (mutation instanceof PatchMutation) {
            i0X.f(encodeDocument(mutation.getKey(), ((PatchMutation) mutation).getValue()));
            i0X.h(encodeDocumentMask(mutation.getFieldMask()));
        } else if (mutation instanceof DeleteMutation) {
            i0X.e(encodeKey(mutation.getKey()));
        } else {
            if (!(mutation instanceof VerifyMutation)) {
                throw Assert.fail("unknown mutation type %s", mutation.getClass());
            }
            i0X.i(encodeKey(mutation.getKey()));
        }
        Iterator<FieldTransform> it = mutation.getFieldTransforms().iterator();
        while (it.hasNext()) {
            i0X.c(encodeFieldTransform(it.next()));
        }
        if (!mutation.getPrecondition().isNone()) {
            i0X.d(encodePrecondition(mutation.getPrecondition()));
        }
        return (K0) i0X.m359build();
    }

    public z0 encodeQueryTarget(Target target) {
        y0 y0VarK = z0.k();
        Z zY = u0.y();
        ResourcePath path = target.getPath();
        if (target.getCollectionGroup() != null) {
            Assert.hardAssert(path.length() % 2 == 0, "Collection Group queries should be within a document path or root.", new Object[0]);
            y0VarK.c(encodeQueryPath(path));
            C1970a0 c1970a0J = C1972b0.j();
            c1970a0J.d(target.getCollectionGroup());
            c1970a0J.c();
            zY.c(c1970a0J);
        } else {
            Assert.hardAssert(path.length() % 2 != 0, "Document queries with filters are not supported.", new Object[0]);
            y0VarK.c(encodeQueryPath(path.popLast()));
            C1970a0 c1970a0J2 = C1972b0.j();
            c1970a0J2.d(path.getLastSegment());
            zY.c(c1970a0J2);
        }
        if (target.getFilters().size() > 0) {
            zY.i(encodeFilters(target.getFilters()));
        }
        Iterator<OrderBy> it = target.getOrderBy().iterator();
        while (it.hasNext()) {
            zY.d(encodeOrderBy(it.next()));
        }
        if (target.hasLimit()) {
            M mI = N.i();
            mI.c((int) target.getLimit());
            zY.f(mI);
        }
        if (target.getStartAt() != null) {
            C1995n c1995nJ = C1997o.j();
            c1995nJ.c(target.getStartAt().getPosition());
            c1995nJ.d(target.getStartAt().isInclusive());
            zY.h(c1995nJ);
        }
        if (target.getEndAt() != null) {
            C1995n c1995nJ2 = C1997o.j();
            c1995nJ2.c(target.getEndAt().getPosition());
            c1995nJ2.d(!target.getEndAt().isInclusive());
            zY.e(c1995nJ2);
        }
        y0VarK.d(zY);
        return (z0) y0VarK.m359build();
    }

    public Y encodeStructuredAggregationQuery(z0 z0Var, List<AggregateField> list, HashMap<String, String> map) {
        X xH = Y.h();
        xH.d(z0Var.j());
        ArrayList arrayList = new ArrayList();
        HashSet hashSet = new HashSet();
        int i6 = 1;
        for (AggregateField aggregateField : list) {
            if (!hashSet.contains(aggregateField.getAlias())) {
                hashSet.add(aggregateField.getAlias());
                StringBuilder sb = new StringBuilder("aggregate_");
                int i7 = i6 + 1;
                sb.append(i6);
                String string = sb.toString();
                map.put(string, aggregateField.getAlias());
                S sJ = e4.W.j();
                C1988j0 c1988j0I = C1990k0.i();
                c1988j0I.c(aggregateField.getFieldPath());
                C1990k0 c1990k0 = (C1990k0) c1988j0I.m359build();
                if (aggregateField instanceof AggregateField.CountAggregateField) {
                    sJ.e(T.f());
                } else if (aggregateField instanceof AggregateField.SumAggregateField) {
                    U uG = V.g();
                    uG.c(c1990k0);
                    sJ.f((V) uG.m359build());
                } else {
                    if (!(aggregateField instanceof AggregateField.AverageAggregateField)) {
                        throw new RuntimeException("Unsupported aggregation");
                    }
                    P pG = Q.g();
                    pG.c(c1990k0);
                    sJ.d((Q) pG.m359build());
                }
                sJ.c(string);
                arrayList.add((e4.W) sJ.m359build());
                i6 = i7;
            }
        }
        xH.c(arrayList);
        return (Y) xH.m359build();
    }

    public A0 encodeTarget(TargetData targetData) {
        v0 v0VarL = A0.l();
        Target target = targetData.getTarget();
        if (target.isDocumentQuery()) {
            v0VarL.c(encodeDocumentsTarget(target));
        } else {
            v0VarL.e(encodeQueryTarget(target));
        }
        v0VarL.i(targetData.getTargetId());
        if (!targetData.getResumeToken().isEmpty() || targetData.getSnapshotVersion().compareTo(SnapshotVersion.NONE) <= 0) {
            v0VarL.h(targetData.getResumeToken());
        } else {
            v0VarL.f(encodeTimestamp(targetData.getSnapshotVersion().getTimestamp()));
        }
        if (targetData.getExpectedCount() != null && (!targetData.getResumeToken().isEmpty() || targetData.getSnapshotVersion().compareTo(SnapshotVersion.NONE) > 0)) {
            M mI = N.i();
            mI.c(targetData.getExpectedCount().intValue());
            v0VarL.d(mI);
        }
        return (A0) v0VarL.m359build();
    }

    public R0 encodeTimestamp(Timestamp timestamp) {
        com.google.protobuf.Q0 q0K = R0.k();
        q0K.d(timestamp.getSeconds());
        q0K.c(timestamp.getNanoseconds());
        return (R0) q0K.m359build();
    }

    public C1996n0 encodeUnaryOrFieldFilter(FieldFilter fieldFilter) {
        FieldFilter.Operator operator = fieldFilter.getOperator();
        FieldFilter.Operator operator2 = FieldFilter.Operator.EQUAL;
        if (operator == operator2 || fieldFilter.getOperator() == FieldFilter.Operator.NOT_EQUAL) {
            e4.r0 r0VarK = t0.k();
            r0VarK.c(encodeFieldPath(fieldFilter.getField()));
            if (Values.isNanValue(fieldFilter.getValue())) {
                r0VarK.d(fieldFilter.getOperator() == operator2 ? s0.IS_NAN : s0.IS_NOT_NAN);
                C1992l0 c1992l0N = C1996n0.n();
                c1992l0N.e(r0VarK);
                return (C1996n0) c1992l0N.m359build();
            }
            if (Values.isNullValue(fieldFilter.getValue())) {
                r0VarK.d(fieldFilter.getOperator() == operator2 ? s0.IS_NULL : s0.IS_NOT_NULL);
                C1992l0 c1992l0N2 = C1996n0.n();
                c1992l0N2.e(r0VarK);
                return (C1996n0) c1992l0N2.m359build();
            }
        }
        C1982g0 c1982g0M = C1986i0.m();
        c1982g0M.c(encodeFieldPath(fieldFilter.getField()));
        c1982g0M.d(encodeFieldFilterOperator(fieldFilter.getOperator()));
        c1982g0M.e(fieldFilter.getValue());
        C1992l0 c1992l0N3 = C1996n0.n();
        c1992l0N3.d(c1982g0M);
        return (C1996n0) c1992l0N3.m359build();
    }

    public R0 encodeVersion(SnapshotVersion snapshotVersion) {
        return encodeTimestamp(snapshotVersion.getTimestamp());
    }

    public boolean isLocalResourceName(ResourcePath resourcePath) {
        return isValidResourceName(resourcePath) && resourcePath.getSegment(1).equals(this.databaseId.getProjectId()) && resourcePath.getSegment(3).equals(this.databaseId.getDatabaseId());
    }

    public Target decodeQueryTarget(z0 z0Var) {
        return decodeQueryTarget(z0Var.i(), z0Var.j());
    }
}
