using System;
using Interfaces;

namespace IrDaemonNotifier
{
    public class IrDaemonNotifier : INotifierProvider
    {
        private readonly ILoggerService _logger;

        public IrDaemonNotifier(ILoggerService logger)
        {
            _logger = logger;
        }

        public string GetDisplayName()
        {
            return "Ir Daemon Notifier";
        }

        public PluginDetails GetPluginDetails()
        {
            return Resources.Details;
        }

        public void NotifyRaceStarted(NotificationEventArgs args)
        {
            try
            {
                var communicator = new IrDaemonCommunicator(_logger);
                communicator.SendCommand(Commands.StartNewRace);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "IrDaemonNotifier NotifyRaceStarted Error");
            }
        }

        public void NotifyRaceStarting(NotificationEventArgs args)
        {
        }

        public void NotifyRaceLapEvent(NotificationEventArgs args, Pilot pilot)
        {
        }

        public void NotifyRaceWinner(NotificationEventArgs args, Pilot pilot)
        {
        }

        public void NotifyRaceFinished(NotificationEventArgs args)
        {
            try
            {
                var communicator = new IrDaemonCommunicator(_logger);
                communicator.SendCommand(Commands.Reset);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "IrDaemonNotifier NotifyRaceFinished Error");
            }
        }

    }
}
