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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use crateSupplierRegistry;
use crateBasicSupplierGroup;
use crateSupplierError;
/// Adds a single supplier from the registry into a group by name.
///
/// This function looks up a supplier by its name in the provided `SupplierRegistry`,
/// and if found, adds it into the given `BasicSupplierGroup`.
///
/// Returns:
/// - `Ok(())` if the supplier was found and added successfully
/// - `Err(SupplierError::NotFound)` if the supplier name does not exist in the registry
///
/// # Example
///
/// ```rust
/// use supplier_kit::supplier::{Supplier, SupplierRegistry};
/// use supplier_kit::supplier_group::{BasicSupplierGroup};
/// use supplier_kit::utils::add_supplier_from_registry;
/// use supplier_kit::errors::SupplierError;
///
/// struct DummySupplier;
///
/// impl Supplier for DummySupplier {
/// fn name(&self) -> &str { "dummy" }
/// fn query(&self, _request: supplier_kit::models::SupplierRequest)
/// -> Result<supplier_kit::models::SupplierResponse, SupplierError> {
/// Err(SupplierError::Timeout)
/// }
/// }
///
/// let mut registry = SupplierRegistry::new();
/// registry.register("dummy", DummySupplier);
///
/// let mut group = BasicSupplierGroup::new("group1");
/// let result = add_supplier_from_registry(&mut group, ®istry, "dummy");
/// assert!(result.is_ok());
/// ```
/// Adds multiple suppliers from the registry into a group by their names.
///
/// Iterates through a list of supplier names, tries to fetch each from the registry,
/// and adds all valid ones into the given `BasicSupplierGroup`.
///
/// Returns a list of failures: for each name not found in the registry, a tuple of
/// `(name, SupplierError::NotFound)` is returned.
///
/// # Example
///
/// ```rust
/// use supplier_kit::supplier::{Supplier, SupplierRegistry};
/// use supplier_kit::supplier_group::{BasicSupplierGroup};
/// use supplier_kit::utils::add_suppliers_from_registry;
/// use supplier_kit::errors::SupplierError;
///
/// struct DummySupplier;
///
/// impl Supplier for DummySupplier {
/// fn name(&self) -> &str { "dummy" }
/// fn query(&self, _request: supplier_kit::models::SupplierRequest)
/// -> Result<supplier_kit::models::SupplierResponse, SupplierError> {
/// Ok(supplier_kit::models::SupplierResponse {
/// data: serde_json::json!({ "ok": true }),
/// })
/// }
/// }
///
/// let mut registry = SupplierRegistry::new();
/// registry.register("dummy", DummySupplier);
///
/// let mut group = BasicSupplierGroup::new("group2");
/// let failures = add_suppliers_from_registry(&mut group, ®istry, &["dummy", "not_found"]);
///
/// assert_eq!(failures.len(), 1);
/// assert_eq!(failures[0].0, "not_found");
/// ```