using System.Collections.Generic;
using Net.Eagle0.Eagle.Common;
using Net.Eagle0.Eagle.Views;
using static Net.Eagle0.Eagle.Common.ActionResultType;

namespace eagle.Notifications {
    public static class NotificationDispatcher {
        private static readonly Dictionary<ActionResultType, NotificationGenerator>
                _typeGeneratorMap = new() {
                    { ArmyWithdrew, ArmyWithdrewNotificationGenerator.Generator },
                    { EpidemicTookEffect, ProvinceEventsNotificationGenerator.Generator },
                    { FactionDestroyed, FactionDestroyedNotificationGenerator.Generator },
                    { FailedSwearBrotherhood,
                      FailedSwearBrotherhoodNotificationGenerator.Generator },
                    { GameEnded, GameEndedNotificationGenerator.Generator },
                    { NewRoundAction, NewRoundNotificationGenerator.Generator },
                    { PrisonerEscaped, PrisonerEscapedNotificationGenerator.Generator },
                    { PrisonerReturnTookEffect, PrisonerReturnedNotificationGenerator.Generator },
                    { ProvinceConquered, ProvinceConqueredNotificationGenerator.Generator },
                    { ProvinceEventsChanged, ProvinceEventsNotificationGenerator.Generator },
                    { RiotAverted, RiotAvertedNotificationGenerator.Generator },
                    { RiotOccurred, RiotOccurredNotificationGenerator.Generator },
                    { RiotSuppressed, RiotSuppressedNotificationGenerator.Generator },
                    { WeatherForcedSuppliesBack,
                      WeatherForcedSuppliesBackNotificationGenerator.Generator },
                    { WeatherForcedSuppliesLost,
                      WeatherForcedSuppliesLostNotificationGenerator.Generator },
                    { WeatherForcedTurnBack, WeatherForcedTurnBackNotificationGenerator.Generator },
                    { WeatherTookEffect, ProvinceEventsNotificationGenerator.Generator },
                };

        public static IEnumerable<Notification> GenerateNotifications(
                ActionResultView actionResultView,
                IGameModel currentModel) {
            foreach (var result in ARNNotificationDispatcher.GenerateNotifications(
                             actionResultView,
                             currentModel)) {
                yield return result;
            }

            if (_typeGeneratorMap.TryGetValue(actionResultView.Type, out var gen)) {
                foreach (var result in gen(actionResultView, currentModel)) { yield return result; }
            }
        }
    }
}