namespace ms_namingservice.Mapping.ValuesMapping.TempMapping;

/// <summary>
/// This class provides a method for converting an Input object's tags to a standard format.
/// </summary>
public class TagFixing
{
    /// <summary>
    /// Converts an Input object's tags to a standard format where the tags array always has a length of 2 and may contain null values.
    /// </summary>
    /// <param name="input">The Input object whose tags are to be converted.</param>
    /// <returns>The Input object with its tags converted to the standard format.</returns>
    public static Input GetConvertedTagInput(Input input)
    {
        //Check the tags structure in order to not force the IndexArrayOutbound exception in the microservice
        //Standard tag input should be
        //Tag[0] = MITRE category/tactic
        //Tag[1] = MITRE subcategory/technique
        //In order some of it is missing, it is replaced with "null" string
        if (!(input.Tags != null && input.Tags.Length == 2 && input.Tags[0] == null && input.Tags[1] == null))
        {
            {
                if (input.Tags.Length == 1 && !input.Tags[0].StartsWith("attack.t"))
                {
                    string category = input.Tags[0];
                    input.Tags = new string[2] { category, "null" };
                }

                if (input.Tags.Length == 1 && input.Tags[0].StartsWith("attack.t"))
                {
                    string subcategory = input.Tags[0];
                    input.Tags = new string[2] { "null", subcategory };
                }

                if (input.Tags.Length == 0)
                {
                    input.Tags = new string[2] { "null", "null" };
                }
            }
        }

        return input; //Returning converted input
    }
}