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

namespace Valg.Eva.Skanning.Scan.Presentation.ReadSoftModel.FieldValidators
{
    public class BallotNoFieldValidator : IFieldValidator
    {
        private readonly ISystemSettingsService systemSettingsService;

        public BallotNoFieldValidator(ISystemSettingsService systemSettingsService)
        {
            this.systemSettingsService = systemSettingsService;
        }

        public ScannableFieldType FieldType { get { return ScannableFieldType.BallotNo; } }
        public bool IsFieldValid(ScannedField field, IEnumerable<ScannedField> alreadyAddedFields = null)
        {
            return (
                field.Value.Length == systemSettingsService.GetBallotNumberLength()  &&
                !field.Value.Contains("*") &&
                BallotNumberGenerator.IsBallotNumberCheckSumValid(field.Value));
        }
    }
}
