using System.Collections.Generic;
using System.Linq;
using Valg.EVA.Skanning.ServicesModel.Internal.SystemSettings;

namespace Valg.EVA.Skanning.Services.Scan
{
    public class BallotIdValidator
    {
        private readonly List<int> validBallotIdLengths;

        public BallotIdValidator(ISystemSettingsProvider systemSettingsProvider)
        {
            validBallotIdLengths = systemSettingsProvider.GetValidLengthsForBallotId();
        }

        public bool IsValid(string valueToValidate)
        {
            return CorrectLength(valueToValidate) && IsNumber(valueToValidate);
        }

        private bool IsNumber(string value)
        {
            var isNumber = value.All(char.IsDigit);
            return isNumber;
        }

        private bool CorrectLength(string value)
        {
            return !string.IsNullOrWhiteSpace(value) && validBallotIdLengths.Contains(value.Length);
        }
    }
}
