using Valg.EVA.Skanning.UserInterfaceElements.Commands;
using Valg.EVA.Skanning.UserInterfaceElements.EventArgs;
using System;
using System.Collections.ObjectModel;
using System.Windows.Input;

namespace Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.Candidate
{
    public class PersonVoteContextMenuCommand
    {
        private ObservableCollection<ContextMenuViewModel> commandList;
        private readonly RelayCommand givePersonVoteCommand;
        private readonly RelayCommand removePersonVoteCommand;

        public PersonVoteContextMenuCommand()
        {
            givePersonVoteCommand = new RelayCommand(param => ExecutePersonVote(true));
            removePersonVoteCommand = new RelayCommand(param => ExecutePersonVote(false));
        }

        public ObservableCollection<ContextMenuViewModel> CommandList
        {
            get
            {
                if (commandList == null)
                {
                    commandList = new ObservableCollection<ContextMenuViewModel>
                    {
                        new ContextMenuViewModel {DisplayName = Valg.EVA.Skanning.Resources.Language.VerifyLanguageString.Button_GivePersonVote, Command = GivePersonVoteCommand},
                        new ContextMenuViewModel {DisplayName = Valg.EVA.Skanning.Resources.Language.VerifyLanguageString.Button_RemovePersonVote, Command = RemovePersonVoteCommand}
                    };
                }

                return commandList;
            }
        }

        public event EventHandler<CustomEventArgs> ContextMenuCommandWasExecuted;

        private ICommand GivePersonVoteCommand { get { return givePersonVoteCommand; } }

        private ICommand RemovePersonVoteCommand { get { return removePersonVoteCommand; } }

        private void ExecutePersonVote(bool giveVote)
        {
            if (ContextMenuCommandWasExecuted != null)
            {
                ContextMenuCommandWasExecuted(this, new CustomEventArgs(giveVote));
            }
        }
    }
}
