using Valg.EVA.Skanning.Resources.Language;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Prism.Commands;
using Valg.EVA.Skanning.JobManagement.Startup.UI.Duplicates.Events;

namespace Valg.EVA.Skanning.JobManagement.Startup.UI.Duplicates
{
    public class BallotDetailsViewModel : ReactiveViewModel
    {
        private IEnumerable<DuplicateBallotModel> duplicates;

        public BallotDetailsViewModel()
        {
            ShowImagesCommand = new DelegateCommand(ShowImages);
        }

        public void Initialize(string value, IEnumerable<DuplicateBallotModel> dupes, List<InBoxDetailsViewModel> inBoxDetailsViewModel)
        {
            Value = value;
            duplicates = dupes;
            BoxesContainingBallot = inBoxDetailsViewModel.OrderBy(p => p.BoxNumber).ToList();
        }

        public ICommand ShowImagesCommand { get; private set; }

        public List<InBoxDetailsViewModel> BoxesContainingBallot { get; private set; }

        public int DuplicateCount => duplicates.Count();

        public string Value { get; private set; }

        public string Description => string.Format(JobManagementLanguageString.Duplicates_BallotDetailsView_BallotDescription, Value, DuplicateCount);

        private void ShowImages()
        {
            var args = new ViewImagesEventArgs();
            args.BallotsToSee.AddRange(duplicates);
            PublishEvent<ViewImagesEvent, ViewImagesEventArgs>(args);
        }
    }
}
