use std::path::PathBuf;
use crate::merge::WinnerMap;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SourceKind {
Str,
File,
OptionalFile,
FindFile,
}
#[derive(Debug, Clone)]
pub struct SourceEntry {
pub source_id: usize,
pub source_kind: SourceKind,
pub label: String,
pub path: Option<PathBuf>,
pub required: bool,
pub found: bool,
pub digest: Option<String>,
pub size_bytes: Option<u64>,
pub source_root: Option<PathBuf>,
pub source_parent: Option<PathBuf>,
}
#[derive(Debug, Clone, Default)]
pub struct SourceReport {
pub entries: Vec<SourceEntry>,
}
impl SourceReport {
#[must_use]
pub fn has_missing_required(&self) -> bool {
self.entries.iter().any(|e| e.required && !e.found)
}
pub fn found_entries(&self) -> impl Iterator<Item = &SourceEntry> {
self.entries.iter().filter(|e| e.found)
}
pub fn missing_optional_entries(&self) -> impl Iterator<Item = &SourceEntry> {
self.entries.iter().filter(|e| !e.required && !e.found)
}
}
#[derive(Debug, Clone)]
pub struct LayerEntry {
pub layer_id: usize,
pub layer_name: String,
pub priority: usize,
pub source_id: usize,
pub digest: String,
pub layer_order_digest: String,
pub winning_field_map: WinnerMap,
}
#[derive(Debug, Clone, Default)]
pub struct LayerReport {
pub entries: Vec<LayerEntry>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CoercedType {
Bool,
Integer,
Float,
Str,
}
impl std::fmt::Display for CoercedType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Bool => write!(f, "bool"),
Self::Integer => write!(f, "integer"),
Self::Float => write!(f, "float"),
Self::Str => write!(f, "str"),
}
}
}
#[derive(Debug, Clone)]
pub struct EnvOverrideEntry {
pub raw_env_key: String,
pub configured_prefix: String,
pub mapped_path: String,
pub raw_value_digest: String,
pub coerced_type: Option<CoercedType>,
pub coerced_value_digest: Option<String>,
pub accepted: bool,
pub rejection_code: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct EnvOverrideReport {
pub prefix: String,
pub entries: Vec<EnvOverrideEntry>,
}
impl EnvOverrideReport {
pub fn accepted(&self) -> impl Iterator<Item = &EnvOverrideEntry> {
self.entries.iter().filter(|e| e.accepted)
}
pub fn rejected(&self) -> impl Iterator<Item = &EnvOverrideEntry> {
self.entries.iter().filter(|e| !e.accepted)
}
}
#[must_use]
pub fn blake3_hex(data: &[u8]) -> String {
blake3::hash(data).to_hex().to_string()
}