using System.Collections.ObjectModel;
using Valg.EVA.Skanning.Entity.ReadModel;
using Valg.EVA.Skanning.ServicesModel.Internal.Interpreter.Modifications;
using Valg.EVA.Skanning.ServicesModel.Internal.SystemSettings;

namespace Valg.EVA.Skanning.ServicesModel.Internal.Interpreter
{
    public class CountingOnTopLevelInterpreter
    {
        private readonly ISystemSettingsProvider systemSettings;

        public CountingOnTopLevelInterpreter(ISystemSettingsProvider systemSettings)
        {
            this.systemSettings = systemSettings;
        }
        
        
        
        
        
        
        
        
        
        
        public void AdjustValidationRulesIfCountedOnLowerLevel(BoxCounting boxCounting, BallotPaperInBoxCounting ballotPaper, ReadOnlyCollection<BallotPaperFieldValue> ballotPaperFieldValues, InterpreterModificationBuffer modificationBuffer)
        {
            var additionalElectionConfiguration = systemSettings.GetAdditionalElectionConfiguration(boxCounting.ElectionEventId, boxCounting.ElectionIdentifier, boxCounting.ElectionGroup, boxCounting.ContestId);

            if (additionalElectionConfiguration.AlsoCountedOnLowerLevels 
                && !boxCounting.IsCurrentlyCountedByTopLevelCountingAuthority())
            {
                modificationBuffer.SetBallotPaperToBeMarkedAsIgnoreCandidates(ballotPaper);
                modificationBuffer.SetCorrectionFieldsToNotNeedingVerification(ballotPaperFieldValues);
            }
        }
    }
}
