using System.Linq;
namespace StellaOps.DistroIntel;
public static partial class DistroMappings
{
///
/// Finds derivatives for a canonical (parent) distro at a specific major release.
/// Use this to find alternative evidence sources when native OVAL/CSAF is unavailable.
///
/// The canonical distro identifier (e.g., "rhel").
/// The major release version.
/// Matching derivative mappings, ordered by confidence (High first).
///
/// var derivatives = DistroMappings.FindDerivativesFor("rhel", 9);
/// // Returns: [(rhel, almalinux, 9, High), (rhel, rocky, 9, High), (rhel, oracle, 9, High)]
///
public static IEnumerable FindDerivativesFor(string canonicalDistro, int majorRelease)
{
var key = (canonicalDistro.ToLowerInvariant(), majorRelease);
if (_byCanonicalIndex.TryGetValue(key, out var derivatives))
{
return derivatives.OrderByDescending(d => d.Confidence);
}
return [];
}
///
/// Finds the canonical (parent) distro for a derivative distro.
/// Use this to map a derivative back to its upstream source.
///
/// The derivative distro identifier (e.g., "almalinux").
/// The major release version.
/// The canonical mapping if found, null otherwise.
///
/// var canonical = DistroMappings.FindCanonicalFor("almalinux", 9);
/// // Returns: (rhel, almalinux, 9, High)
///
public static DistroDerivative? FindCanonicalFor(string derivativeDistro, int majorRelease)
{
var key = (derivativeDistro.ToLowerInvariant(), majorRelease);
return _byDerivativeIndex.GetValueOrDefault(key);
}
///
/// Gets the confidence multiplier for a derivative relationship.
/// Apply this to the base confidence when using derivative evidence.
///
/// The derivative confidence level.
/// Multiplier value (0.95 for High, 0.80 for Medium).
public static decimal GetConfidenceMultiplier(DerivativeConfidence confidence)
{
return confidence switch
{
DerivativeConfidence.High => 0.95m,
DerivativeConfidence.Medium => 0.80m,
_ => 0.70m // Unknown - conservative
};
}
}