using System;
using System.Collections.Generic;
using FishDice.LuckyDice;

namespace FishDice.Demo
{
    public sealed class ScriptedRandomSource : IRandomSource
    {
        private readonly Queue<int> _values;

        public ScriptedRandomSource(IEnumerable<int> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            _values = new Queue<int>(values);
        }

        public int Next(int minInclusive, int maxExclusive)
        {
            if (_values.Count == 0)
            {
                throw new InvalidOperationException("Scripted demo random values were exhausted.");
            }

            var value = _values.Dequeue();
            if (value < minInclusive || value >= maxExclusive)
            {
                throw new ArgumentOutOfRangeException(
                    nameof(value),
                    value,
                    $"Expected scripted random value in [{minInclusive}, {maxExclusive}).");
            }

            return value;
        }
    }
}
