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

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

        private static IEnumerable<Notification> GenerateNotification(
                ActionResultView actionResultView,
                IGameModel currentModel) {
            var playerId = currentModel.PlayerId;
            var province = currentModel.Provinces[actionResultView.Province.Value];
            if (province.RulingFactionId.HasValue && province.RulingFactionId.Value == playerId) {
                string noteTitle = "Army Withdrew";
                string noteText =
                        $"{currentModel.FactionName(actionResultView.Player.Value)}'s army withdrew from you in {province.Name}.";

                var faction = currentModel.MaybeDestroyedFaction(actionResultView.Player.Value);
                var factionHead = currentModel.Heroes[faction.FactionHeadId];

                yield return new Notification(
                        title: noteTitle,
                        text: noteText,
                        singleProvinceId: province.Id,
                        singleDisplayedHero: factionHead);
            }
        }
    }
}