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

namespace SoulstormReplayReader.Core.Domain.Player;

public class PlayerBugChecker
{
    private 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;
    }
}