package com.google.firebase.firestore;

import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.ResourcePath;
import com.google.firebase.firestore.util.Executors;
import com.google.firebase.firestore.util.Preconditions;
import com.google.firebase.firestore.util.Util;

/* JADX INFO: loaded from: classes3.dex */
public class CollectionReference extends Query {
    public CollectionReference(ResourcePath resourcePath, FirebaseFirestore firebaseFirestore) {
        super(com.google.firebase.firestore.core.Query.atPath(resourcePath), firebaseFirestore);
        if (resourcePath.length() % 2 == 1) {
            return;
        }
        throw new IllegalArgumentException("Invalid collection reference. Collection references must have an odd number of segments, but " + resourcePath.canonicalString() + " has " + resourcePath.length());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static /* synthetic */ DocumentReference lambda$add$0(DocumentReference documentReference, Task task) {
        task.getResult();
        return documentReference;
    }

    public Task<DocumentReference> add(Object obj) {
        Preconditions.checkNotNull(obj, "Provided data must not be null.");
        DocumentReference documentReferenceDocument = document();
        return documentReferenceDocument.set(obj).continueWith(Executors.DIRECT_EXECUTOR, new c(documentReferenceDocument, 0));
    }

    public DocumentReference document() {
        return document(Util.autoId());
    }

    public String getId() {
        return this.query.getPath().getLastSegment();
    }

    public DocumentReference getParent() {
        ResourcePath resourcePathPopLast = this.query.getPath().popLast();
        if (resourcePathPopLast.isEmpty()) {
            return null;
        }
        return new DocumentReference(DocumentKey.fromPath(resourcePathPopLast), this.firestore);
    }

    public String getPath() {
        return this.query.getPath().canonicalString();
    }

    public DocumentReference document(String str) {
        Preconditions.checkNotNull(str, "Provided document path must not be null.");
        return DocumentReference.forPath(this.query.getPath().append(ResourcePath.fromString(str)), this.firestore);
    }
}
