using RpgRoller.Contracts;
using RpgRoller.Domain;

namespace RpgRoller.Services;

public sealed class StandardRollEngine(IDiceRoller diceRoller)
{
    public (int Total, string Breakdown, IReadOnlyList<RollDieResult> Dice) Roll(DiceExpression expression)
    {
        var diceValues = new int[expression.DiceCount];
        var dice = new RollDieResult[expression.DiceCount];
        var total = expression.Modifier;
        for (var i = 0; i < expression.DiceCount; i += 1)
        {
            var value = diceRoller.Roll(expression.Sides);
            diceValues[i] = value;
            dice[i] = new(value, false, false, false, false, false);
            total += value;
        }

        return (total, RollBreakdownFormatter.BuildBreakdown(diceValues, expression.Modifier, total), dice);
    }
}