using System.Collections.Generic;
using Valg.EVA.Skanning.Scan.ReadSoftContracts.Model;
using Valg.EVA.Skanning.Services.SystemSettings;

namespace Valg.Eva.Skanning.Scan.Presentation.ReadSoftModel.FieldValidators
{
    public class MultipleStampsFieldValidator : IFieldValidator
    {
        private readonly decimal fillPercentageLimit;

        public MultipleStampsFieldValidator(ISystemSettingsService systemSettingsService)
        {
            fillPercentageLimit = systemSettingsService.GetStampFillPercentageMinimum();
        }

        public ScannableFieldType FieldType { get { return ScannableFieldType.MultipleStamps; } }

        public bool IsFieldValid(ScannedField field, IEnumerable<ScannedField> alreadyAddedFields = null)
        {
            return 
                fillPercentageLimit == 0 ||
                IsStampValid(int.Parse(field.Value));
        }

        private bool IsStampValid(int fillingPercentage)
        {
            return (fillingPercentage >= fillPercentageLimit);
        }
    }
}
