using System.Text;
using SoulstormReplayReader.Core.Domain.Action;
using SoulstormReplayReader.Core.Domain.BugCheckers;

namespace SoulstormReplayReader.Core.Domain.Player;

public class PlayerBugChecker
{
    public readonly List<BugCheckerBase> BugCheckers = new();

    public PlayerBugChecker Add(BugCheckerBase checker)
    {
        BugCheckers.Add(checker);
        return this;
    }

    public void Check(IGameAction action)
    {
        BugCheckers.ForEach(bugChecker => bugChecker.Check(action));
    }

    public bool HasAccusations() => BugCheckers.Any(checker => checker.HasAccusation);

    public string GetAccusationsList()
    {
        var sb = new StringBuilder();

        foreach (var checker in BugCheckers.Where(checker => checker.HasAccusation))
        {
            sb.AppendLine(checker.Accusation);
        }

        var accusationsList = sb.ToString();

        if (string.IsNullOrEmpty(accusationsList))
            return null;

        return accusationsList;
    }
}