using System.Collections.Generic;
using System.Linq;
using Valg.EVA.Skanning.Contracts.CommonEnums;
using Valg.EVA.Skanning.Entity.ReadModel;
using Valg.EVA.Skanning.Repositories.BallotPaper;

namespace Valg.EVA.Skanning.ServicesModel.Internal.Verification
{
    public class InitialFieldValuesResolver : IInitialFieldValuesResolver
    {
        private readonly IBallotPaperRepository ballotPaperRepository;

        public InitialFieldValuesResolver(IBallotPaperRepository ballotPaperRepository)
        {
            this.ballotPaperRepository = ballotPaperRepository;
        }

        public List<BallotPaperFieldValue> GetInitialFieldValues(int ballotPaperId)
        {
            var fieldValuesFromScanner = ballotPaperRepository.GetFieldValues(ballotPaperId, ValueSourceType.Scan);
            var fieldValuesFromInterpreter = ballotPaperRepository.GetFieldValues(ballotPaperId, ValueSourceType.StateInterpreter);
            return fieldValuesFromInterpreter.Union(fieldValuesFromScanner, new ScanAndInterpretFieldValueMergeComparer()).ToList();
        }
    }
}
