using System.Collections.Generic;
using Valg.EVA.Skanning.Scan.ReadSoftContracts.Model;
using Valg.EVA.Skanning.ServicesModel.Internal.Validation;

namespace Valg.Eva.Skanning.Scan.Presentation.ReadSoftModel.FieldValidators
{
    public class RefOptFieldValidator : IFieldValidator
    {
        private readonly FillPercentageRangeChecker rangeChecker;

        public RefOptFieldValidator(FillPercentageRangeCheckerFactory fillPercentageRangeCheckerFactory)
        {
            rangeChecker = fillPercentageRangeCheckerFactory.GetGeneralPartyVoteRangeChecker();
        }

        public ScannableFieldType FieldType { get { return ScannableFieldType.Ref_opt; } }
        public bool IsFieldValid(ScannedField field, IEnumerable<ScannedField> alreadyAddedFields = null)
        {
            return IsRefOptValid(int.Parse(field.Value));
        }

        private bool IsRefOptValid(int fillPercentage)
        {
            return rangeChecker.IsInsideRange(fillPercentage);
        }
    }
}
