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

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

        private static IEnumerable<Notification> GenerateNotification(
                ActionResultView actionResultView,
                IGameModel currentModel) {
            var province = currentModel.Provinces[actionResultView.Province.Value];

            if (actionResultView.Player.Value == currentModel.PlayerId) {
                var returnedToProvinceId = actionResultView.GameStateDiff.ChangedProvinces
                                                   .First(pvd => pvd.NewIncomingArmies.Any())
                                                   .Id;
                var returnedToProvince = currentModel.Provinces[returnedToProvinceId];
                string noteTitle = "Supplies Returned";
                string noteText =
                        $"We were unable to reach {province.Name} due to weather, and our supplies were returned to {returnedToProvince.Name}";

                yield return new Notification(noteTitle, noteText, province.Id);
            }
        }
    }
}