using eSuite.WorkBench.Services;
using eSuite.WorkBench.WpfHelper;
using System;

using System.Threading.Tasks;

namespace eSuite.WorkBench.Commands
{
    public class RestoreDatabaseCommand : AsyncCommandBase
    {
        private readonly MainWindowViewModel _mainWindowViewModel;
        private readonly IDbService _dbService;

        public RestoreDatabaseCommand(MainWindowViewModel mainWindowViewModel, IDbService dbService, Action<Exception> onException, EventHandler<FeedbackEventArgs> addFeedbackMessage) : base(onException)
        {
            FeedbackMessage += addFeedbackMessage;
            _mainWindowViewModel = mainWindowViewModel;
            _dbService = dbService;
        }

        protected override async Task ExecuteAsync(object parameter)
        {
            DoFeedbackMessage("Restorting database...");
            await _dbService.RestoreDatabaseAsync(_mainWindowViewModel.DatabaseBackups.SelectedItem);
            DoFeedbackMessage("...database restored");
        }
    }
}
