using RobotNet.RobotShares.VDA5050.State;
using System.Text;

namespace RobotNet.RobotShares.VDA5050;

public class VDA5050Helper
{
    public static string ConvertErrorDetail(IEnumerable<Error> errors)
    {
        string errorsType = "";
        foreach (var error in errors)
        {
            if (error == errors.Last()) errorsType += $"{error.ErrorType}";
            else errorsType += $"{error.ErrorType}, ";
        }
        StringBuilder errorStr = new($"Robot có lỗi: [{errorsType}]\n");
        foreach (var error in errors)
        {
            string errorDes = $"- {error.ErrorType}: {error.ErrorDescription}\n";
            errorStr.Append(errorDes.PadLeft(errorDes.Length + 3));
            foreach (var refer in error.ErrorReferences)
            {
                string errorRefer = $"+ {refer.ReferenceKey}: {refer.ReferenceValue}\n";
                errorStr.Append(errorRefer.PadLeft(errorRefer.Length + 9));
            }
        }
        return !errors.Any() ? "" : errorStr.ToString();
    }
}
