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

namespace eagle.Notifications.ARNNotifications {
    public static class ShatteredArmyDetailsNotificationGenerator {
        public static readonly ARNNotificationGenerator Generator = GenerateNotifications;

        private static IEnumerable<Notification> GenerateNotifications(
                Net.Eagle0.Eagle.Common.Notification notification,
                IGameModel currentModel) {
            var details = notification.Details.ShatteredArmyDetails;
            var province = currentModel.Provinces[details.ProvinceId];
            var factionName = currentModel.FactionName(details.FactionId);

            var faction = currentModel.MaybeDestroyedFaction(details.FactionId);
            var factionHead = currentModel.Heroes[faction.FactionHeadId];

            string noteTitle = "Army Shattered";
            string noteText = "";

            switch (details.Reason) {
                case ShatteredArmyDetails.Types.Reason.ShatteredArmyReasonBlizzard:
                    noteText =
                            $"{factionName}'s army was trapped by the blizzard in in {province.Name} and was shattered!";
                    break;

                case ShatteredArmyDetails.Types.Reason.ShatteredArmyReasonWithdraw:
                    noteText =
                            $"{factionName}'s army had nowhere to withdraw to from {province.Name} and was shattered!";
                    break;

                default: throw new ArgumentException("Unknown Shattered Army reason!");
            }

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