using System.Collections.Generic;
using Net.Eagle0.Eagle.Views;

namespace eagle.Notifications {
    public static class FactionDestroyedNotificationGenerator {
        public static readonly NotificationGenerator Generator = GenerateNotification;

        private static IEnumerable<Notification> GenerateNotification(
                ActionResultView actionResultView,
                IGameModel currentModel) {
            foreach (var id in actionResultView.GameStateDiff.RemovedFactionIds) {
                if (id == currentModel.PlayerId) {
                    yield return new Notification(
                            title: "Game Over",
                            text: $"{currentModel.FactionName(id)} has been destroyed! That's you! Your game is OVER!");
                } else {
                    var factionHeadId = currentModel.MaybeDestroyedFaction(id).FactionHeadId;
                    var factionHead = currentModel.Heroes[factionHeadId];
                    yield return new Notification(
                            title: "Faction Destroyed",
                            text: $"{currentModel.FactionName(id)} has been destroyed!",
                            provinceIds: null,
                            singleDisplayedHero: factionHead);
                }
            }
        }
    }
}