use std::collections::HashSet;
use std::path::Path;
use helm_schema_core::ResourceRef;
use crate::cache::{json_files, subdirs};
use crate::inference::cache_scan::match_crd_filename;
#[must_use]
pub(crate) fn collect_other_versions(
cache_root: &Path,
resource: &ResourceRef,
requested_version: &str,
configured_source_ids: &HashSet<String>,
) -> Vec<String> {
let mut out: Vec<String> = Vec::new();
let Some((group, _)) = resource.api_version.split_once('/') else {
return out;
};
let kind_lc = resource.kind.to_ascii_lowercase();
for (source_id, source_path) in subdirs(cache_root) {
if !configured_source_ids.contains(&source_id) {
continue;
}
for path in json_files(&source_path.join(group)) {
let Some(filename) = path.file_name().and_then(|s| s.to_str()) else {
continue;
};
let Some(version) = match_crd_filename(filename, &kind_lc) else {
continue;
};
if version != requested_version {
out.push(version);
}
}
}
out.sort();
out.dedup();
out
}