package com.google.firebase.firestore.core;

import com.google.firebase.database.collection.ImmutableSortedSet;
import com.google.firebase.firestore.core.DocumentViewChange;
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.DocumentSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes3.dex */
public class ViewSnapshot {
    private final List<DocumentViewChange> changes;
    private final boolean didSyncStateChange;
    private final DocumentSet documents;
    private boolean excludesMetadataChanges;
    private boolean hasCachedResults;
    private final boolean isFromCache;
    private final ImmutableSortedSet<DocumentKey> mutatedKeys;
    private final DocumentSet oldDocuments;
    private final Query query;

    public enum SyncState {
        NONE,
        LOCAL,
        SYNCED
    }

    public ViewSnapshot(Query query, DocumentSet documentSet, DocumentSet documentSet2, List<DocumentViewChange> list, boolean z6, ImmutableSortedSet<DocumentKey> immutableSortedSet, boolean z7, boolean z8, boolean z9) {
        this.query = query;
        this.documents = documentSet;
        this.oldDocuments = documentSet2;
        this.changes = list;
        this.isFromCache = z6;
        this.mutatedKeys = immutableSortedSet;
        this.didSyncStateChange = z7;
        this.excludesMetadataChanges = z8;
        this.hasCachedResults = z9;
    }

    public static ViewSnapshot fromInitialDocuments(Query query, DocumentSet documentSet, ImmutableSortedSet<DocumentKey> immutableSortedSet, boolean z6, boolean z7, boolean z8) {
        ArrayList arrayList = new ArrayList();
        Iterator<Document> it = documentSet.iterator();
        while (it.hasNext()) {
            arrayList.add(DocumentViewChange.create(DocumentViewChange.Type.ADDED, it.next()));
        }
        return new ViewSnapshot(query, documentSet, DocumentSet.emptySet(query.comparator()), arrayList, z6, immutableSortedSet, true, z7, z8);
    }

    public boolean didSyncStateChange() {
        return this.didSyncStateChange;
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof ViewSnapshot)) {
            return false;
        }
        ViewSnapshot viewSnapshot = (ViewSnapshot) obj;
        if (this.isFromCache == viewSnapshot.isFromCache && this.didSyncStateChange == viewSnapshot.didSyncStateChange && this.excludesMetadataChanges == viewSnapshot.excludesMetadataChanges && this.query.equals(viewSnapshot.query) && this.mutatedKeys.equals(viewSnapshot.mutatedKeys) && this.documents.equals(viewSnapshot.documents) && this.oldDocuments.equals(viewSnapshot.oldDocuments) && this.hasCachedResults == viewSnapshot.hasCachedResults) {
            return this.changes.equals(viewSnapshot.changes);
        }
        return false;
    }

    public boolean excludesMetadataChanges() {
        return this.excludesMetadataChanges;
    }

    public List<DocumentViewChange> getChanges() {
        return this.changes;
    }

    public DocumentSet getDocuments() {
        return this.documents;
    }

    public ImmutableSortedSet<DocumentKey> getMutatedKeys() {
        return this.mutatedKeys;
    }

    public DocumentSet getOldDocuments() {
        return this.oldDocuments;
    }

    public Query getQuery() {
        return this.query;
    }

    public boolean hasCachedResults() {
        return this.hasCachedResults;
    }

    public boolean hasPendingWrites() {
        return !this.mutatedKeys.isEmpty();
    }

    public int hashCode() {
        return ((((((((this.mutatedKeys.hashCode() + ((this.changes.hashCode() + ((this.oldDocuments.hashCode() + ((this.documents.hashCode() + (this.query.hashCode() * 31)) * 31)) * 31)) * 31)) * 31) + (this.isFromCache ? 1 : 0)) * 31) + (this.didSyncStateChange ? 1 : 0)) * 31) + (this.excludesMetadataChanges ? 1 : 0)) * 31) + (this.hasCachedResults ? 1 : 0);
    }

    public boolean isFromCache() {
        return this.isFromCache;
    }

    public String toString() {
        return "ViewSnapshot(" + this.query + ", " + this.documents + ", " + this.oldDocuments + ", " + this.changes + ", isFromCache=" + this.isFromCache + ", mutatedKeys=" + this.mutatedKeys.size() + ", didSyncStateChange=" + this.didSyncStateChange + ", excludesMetadataChanges=" + this.excludesMetadataChanges + ", hasCachedResults=" + this.hasCachedResults + ")";
    }
}
