using System.Collections.Generic;
using System.Text;
namespace TD.Levels.Editor
{
///
/// Accumulates errors and warnings produced during a bake run. Phases append to the report
/// and can check at phase boundaries to decide whether to abort.
///
///
/// The bake never bails on the first error within a phase — all errors in a phase are
/// collected before the phase reports back. A phase boundary is the place where the pipeline
/// checks and decides whether to continue or abort.
///
public class BakeReport
{
private readonly List _errors = new List();
private readonly List _warnings = new List();
/// Errors collected so far. Hard-error phases abort the bake when this is non-empty.
public IReadOnlyList Errors => _errors;
/// Warnings collected so far. Warnings never abort the bake.
public IReadOnlyList Warnings => _warnings;
/// True if any hard errors have been recorded.
public bool HasErrors => _errors.Count > 0;
/// Total error count.
public int ErrorCount => _errors.Count;
/// Total warning count.
public int WarningCount => _warnings.Count;
/// Records a hard error. The check ID (e.g. "P2-1") is prefixed for traceability.
public void Error(string checkId, string message)
{
_errors.Add($"[{checkId}] {message}");
}
/// Records a soft warning. The check ID (e.g. "P2-8") is prefixed for traceability.
public void Warning(string checkId, string message)
{
_warnings.Add($"[{checkId}] {message}");
}
/// Records an error not associated with a numbered check (e.g. "phase 1 found null authoring").
public void Error(string message)
{
_errors.Add(message);
}
/// Records a warning not associated with a numbered check (e.g. "thumbnail render failed").
public void Warning(string message)
{
_warnings.Add(message);
}
/// Renders the full report as a human-readable string for console logging.
public string Format()
{
var sb = new StringBuilder();
if (_errors.Count > 0)
{
sb.AppendLine($"Errors ({_errors.Count}):");
for (int i = 0; i < _errors.Count; i++)
{
sb.AppendLine($" • {_errors[i]}");
}
}
if (_warnings.Count > 0)
{
sb.AppendLine($"Warnings ({_warnings.Count}):");
for (int i = 0; i < _warnings.Count; i++)
{
sb.AppendLine($" • {_warnings[i]}");
}
}
if (_errors.Count == 0 && _warnings.Count == 0)
{
sb.AppendLine("(no errors or warnings)");
}
return sb.ToString();
}
}
}