1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use crateFirestoreDocument;
use HashMap;
/// Retrieves a field's value from a Firestore document using a dot-separated path.
///
/// This function allows accessing nested fields within a document's map values.
/// For example, given a document with a field `user` which is a map containing
/// a field `name`, you can retrieve the value of `name` using the path `"user.name"`.
///
/// Backticks (`) in field paths are automatically removed, as they are sometimes
/// used by the `struct_path` macro for escaping.
///
/// # Arguments
/// * `doc`: A reference to the [`FirestoreDocument`] to extract the field from.
/// * `field_path`: A dot-separated string representing the path to the desired field.
///
/// # Returns
/// Returns `Some(&gcloud_sdk::google::firestore::v1::value::ValueType)` if the field
/// is found at the specified path, otherwise `None`. The `ValueType` enum holds the
/// actual typed value (e.g., `StringValue`, `IntegerValue`).
///
/// # Examples
/// ```rust
/// use firestore::{firestore_doc_get_field_by_path, FirestoreDocument, FirestoreValue};
/// use gcloud_sdk::google::firestore::v1::MapValue;
/// use std::collections::HashMap;
///
/// let mut fields = HashMap::new();
/// let mut user_map_fields = HashMap::new();
/// user_map_fields.insert("name".to_string(), gcloud_sdk::google::firestore::v1::Value {
/// value_type: Some(gcloud_sdk::google::firestore::v1::value::ValueType::StringValue("Alice".to_string())),
/// });
/// fields.insert("user".to_string(), gcloud_sdk::google::firestore::v1::Value {
/// value_type: Some(gcloud_sdk::google::firestore::v1::value::ValueType::MapValue(MapValue { fields: user_map_fields })),
/// });
///
/// let doc = FirestoreDocument {
/// name: "projects/p/databases/d/documents/c/doc1".to_string(),
/// fields,
/// create_time: None,
/// update_time: None,
/// };
///
/// let name_value_type = firestore_doc_get_field_by_path(&doc, "user.name");
/// assert!(name_value_type.is_some());
/// if let Some(gcloud_sdk::google::firestore::v1::value::ValueType::StringValue(name)) = name_value_type {
/// assert_eq!(name, "Alice");
/// } else {
/// panic!("Expected StringValue");
/// }
///
/// let non_existent_value = firestore_doc_get_field_by_path(&doc, "user.age");
/// assert!(non_existent_value.is_none());
/// ```
/// Internal helper function to recursively navigate the document fields.