using Valg.EVA.Skanning.Contracts;
using Valg.EVA.Skanning.Entity.ReadModel;
using Valg.EVA.Skanning.ServicesModel.ElectionConfig.Model;

namespace Valg.EVA.Skanning.ServicesModel.Internal.CountResult
{
    public class FilterForRenumberInclusion
    {
        private readonly Affiliation affiliation;

        public FilterForRenumberInclusion(Affiliation affiliation)
        {
            this.affiliation = affiliation;
        }


        public bool IsIncluded(BallotPaperFieldValue fieldValue)
        {
            return fieldValue.IsRenumberField()
                && fieldValue.Value != ScannerFieldValueTemplateValues.FieldIsIgnored
                && affiliation.CandidateExistsWithinTheAffiliation(fieldValue.FieldIndex.GetValueOrDefault());
        }
    }
}
