
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Unity.Interception.Utilities;
using Valg.EVA.Skanning.UserInterfaceElements;
using Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.VerifiableViewModelsCollection;

namespace Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.WriteIns
{
    public class WriteInPageViewModel : ViewModelBase, IWriteInPageViewModel
    {
        private int pageIndex;

        public WriteInPageViewModel()
        {
            WriteIns = new ObservableCollection<WriteInViewModel>();
        }

        public int PageIndex
        {
            get { return pageIndex; }
            set
            {
                pageIndex = value;
                WriteIns.ForEach(o => o.PageIndex = value);
            }
        }

        public IEnumerable<IViewModelWithVerifiableContent> GetVerificationFields()
        {
            return WriteIns;
        }

        public ObservableCollection<WriteInViewModel> WriteIns { get; private set; }

        public bool NeedsVerification
        {
            get { return WriteIns.Any(p => p.NeedsVerification); }
        }

        public List<WriteInSelectionItem> CandidateList { get; set; }
        public void ClearWriteIns()
        {
            WriteIns.ForEach(vm => vm.Dispose());
            WriteIns.Clear();
        }
    }
}
