namespace StellaOps.Feedser.Normalization.Identifiers;

/// <summary>
/// Provides canonical normalization helpers for package identifiers.
/// </summary>
public static class IdentifierNormalizer
{
    public static bool TryNormalizePackageUrl(string? value, out string? normalized, out PackageUrl? packageUrl)
    {
        normalized = null;
        packageUrl = null;
        if (!PackageUrl.TryParse(value, out var parsed))
        {
            return false;
        }

        var canonical = parsed!.ToCanonicalString();
        normalized = canonical;
        packageUrl = parsed;
        return true;
    }

    public static bool TryNormalizePackageUrl(string? value, out string? normalized)
    {
        return TryNormalizePackageUrl(value, out normalized, out _);
    }

    public static bool TryNormalizeCpe(string? value, out string? normalized)
    {
        return Cpe23.TryNormalize(value, out normalized);
    }
}
