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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Bistun Linguistic Metadata Service (LMS)
// Copyright (C) 2026 Francis Xavier Wazeter IV
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! # Resource Resolver
//! Crate: `bistun-lms`
//! Ref: [014-LMS-BRDG], [011-LMS-DTO]
//! Location: `crates/bistun-lms/src/core/resource/resolver.rs`
//!
//! **Why**: This module translates abstract linguistic resource `IDs` into actionable, environment-specific physical `URIs`.
//! **Impact**: If this module fails, downstream clients cannot fetch the physical `ICU4X` data blobs required for rendering and segmenting, breaking complex scripts.
//!
//! ### Glossary
//! * **Resource URI**: The fully qualified `URL` or filepath where binary linguistic data is hosted.
use LmsError;
use CapabilityManifest;
/// Translates abstract resource `IDs` into physical `URIs`, mutating the `resources` map in-place.
///
/// Time: `O(N)` map iteration | Space: `O(1)` string allocations
///
/// # Logic Trace (Internal)
/// 1. Check if the [`CapabilityManifest`] requires any resources. If not, return early.
/// 2. Format the environment-specific `base_uri` to guarantee proper trailing slashes.
/// 3. Iterate over the abstract `IDs` (keys) in the `manifest.resources` map.
/// 4. Concatenate the base `URI` with the abstract `ID` (appending a `.postcard` extension).
/// 5. Update the resource value in-place with the fully resolved `URI`.
/// 6. Return success.
///
/// # Examples
/// ```rust
/// # use bistun_core::manifest::CapabilityManifest;
/// # use bistun_lms::core::resource::resolver::resolve_resources;
/// let mut manifest = CapabilityManifest::new("th-TH".to_string());
/// manifest.resources.insert("tri_thai".to_string(), "required".to_string());
///
/// resolve_resources(&mut manifest, "https://cdn.bistun.io/").expect("LMS-TEST: Resolution failed");
/// assert_eq!(
/// manifest.resources.get("tri_thai").expect("LMS-TEST: Key missing"),
/// "https://cdn.bistun.io/tri_thai.postcard"
/// );
/// ```
///
/// # Arguments
/// * `manifest` (&mut [`CapabilityManifest`]): The mutable `DTO` currently flowing through the pipeline.
/// * `base_uri` (&str): The environment-specific base `URI` configured in the active memory pool.
///
/// # Returns
/// * `Result<(), LmsError>`: Returns `Ok(())` upon successful resolution or if no resource is required.
///
/// # Golden I/O
/// * **Input**: `manifest` (with `resources: {"tri_thai": "required"}`), `base_uri: "https://cdn.bistun.io/"`
/// * **Output**: `Ok(())` (manifest resources mutated to `"https://cdn.bistun.io/tri_thai.postcard"`)
///
/// # Errors
/// * Conforms to pipeline signature returning [`LmsError`], but currently infallible as it only performs string concatenation.
///
/// # Panics
/// * None.
///
/// # Safety
/// * Safe synchronous execution.