namespace ms_namingservice.Mapping.ValuesMapping;

/// <summary>
/// This class provides a method to convert a MITRE category to an ENISA category.
/// </summary>
public class MitreToDefaultConvert
{
    /// <summary>
    /// Returns the ENISA category corresponding to the specified MITRE category.
    /// </summary>
    /// <param name="mitreCategory">The MITRE category to convert.</param>
    /// <returns>The corresponding ENISA category, or "Other" if no match is found.</returns>
    public static async Task<string> GetEnisaCategory(string mitreCategory)
    {
        // Define the mapping between MITRE and ENISA categories.
        Dictionary<string, string> categoryMappings = new Dictionary<string, string>
        {
            { "attack.collection", "Abusive Content" },
            { "attack.credential.access", "Intrusions" },
            { "attack.command_and_control", "Intrusions" },
            { "attack.defense_evasion", "Information Security" },
            { "attack.discovery", "Information Gathering" },
            { "attack.execution", "Malicious Code" },
            { "attack.exfiltration", "Information Security" },
            { "attack.impact", "Fraud" },
            { "attack.initial_access", "Intrusion Attempts" },
            { "attack.lateral_movement", "Intrusions" },
            { "attack.persistence", "Intrusions" },
            { "attack.privilege_escalation", "Intrusions" },
            { "attack.reconnaissance", "Information Gathering" },
            { "attack.resource_development", "Availability" },
        };

        if (mitreCategory == null)
        {
            // If the input category is null, default to "Other".
            return "Other";
        }
        
        // Try to find a matching ENISA category for the specified MITRE category.
        if (categoryMappings.TryGetValue(mitreCategory, out string enisaCategory) == false)
        {
            // If no match is found, default to "Other".
            enisaCategory = "Other";
        }

        // Return the corresponding ENISA category.
        return enisaCategory;
    }
}