namespace Inspectron.Epson.Templates.Validation;

public record TemplateValidationResult(
    List<TemplateError> Errors,
    List<TemplateWarning> Warnings)
{
    public bool IsValid => Errors.Count == 0;
    public bool HasWarnings => Warnings.Count > 0;

    public static TemplateValidationResult Valid() => new(new List<TemplateError>(), new List<TemplateWarning>());

    public static TemplateValidationResult WithErrors(params TemplateError[] errors) =>
        new(errors.ToList(), new List<TemplateWarning>());

    public override string ToString()
    {
        if (IsValid && !HasWarnings)
        {
            return "Template is valid.";
        }

        var lines = new List<string>();
        if (Errors.Count > 0)
        {
            lines.Add($"Errors ({Errors.Count}):");
            lines.AddRange(Errors.Select(e => $"  {e}"));
        }
        if (Warnings.Count > 0)
        {
            lines.Add($"Warnings ({Warnings.Count}):");
            lines.AddRange(Warnings.Select(w => $"  {w}"));
        }
        return string.Join(Environment.NewLine, lines);
    }
}
