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

namespace eagle.Notifications {
    using FactionId = Int32;

    public static class WeatherForcedTurnBackNotificationGenerator {
        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) {
                string noteTitle = "Army Turned Back";
                string noteText =
                        $"Our army approaching {province.Name} was forced to turn back due to harsh weather.";

                yield return new Notification(
                        title: noteTitle,
                        text: noteText,
                        singleProvinceId: province.Id);
            } else if (province.RulingFactionId is FactionId fid && fid == currentModel.PlayerId) {
                var faction = currentModel.MaybeDestroyedFaction(actionResultView.Player.Value);
                var factionHead = currentModel.Heroes[faction.FactionHeadId];

                string noteTitle = "Army Turned Back";
                string noteText =
                        $"{DisplayNames.ResolvedFactionString(faction, currentModel)}'s army approaching {province.Name} was forced to turn back due to harsh weather.";

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