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

namespace eagle.Notifications.ARNNotifications {
    using ProvinceId = Int32;

    public static class WithdrewForTruceDetailsNotificationGenerator {
        public static readonly ARNNotificationGenerator Generator = GenerateNotifications;

        private static IEnumerable<Notification> GenerateNotifications(
                Net.Eagle0.Eagle.Common.Notification notification,
                IGameModel currentModel) {
            var playerId = currentModel.PlayerId;
            string noteTitle = "Army Withdrew from Truce Partner";
            string noteText = "";

            HeroView displayedHero = null;

            var details = notification.Details.WithdrewForTruce;
            if (details.WithdrawingFactionId == playerId) {
                noteText += "Your army ";
            } else {
                displayedHero =
                        currentModel
                                .Heroes[currentModel
                                                .MaybeDestroyedFaction(details.WithdrawingFactionId)
                                                .FactionHeadId];
                noteText += $"{currentModel.FactionName(details.WithdrawingFactionId)}'s army ";
            }

            noteText +=
                    $"returned from {currentModel.Provinces[details.WithdrewFromProvinceId].Name} to {currentModel.Provinces[details.WithdrewToProvinceId].Name} because of a treaty with ";

            if (details.WithdrewFromFactionId == playerId) {
                noteText += "you.";
            } else {
                displayedHero = currentModel.Heroes[currentModel
                                                            .MaybeDestroyedFaction(
                                                                    details.WithdrewFromFactionId)
                                                            .FactionHeadId];
                noteText += $"{currentModel.FactionName(details.WithdrewFromFactionId)}.";
            }

            yield return new Notification(
                    title: noteTitle,
                    text: noteText,
                    provinceIds: new List<
                            ProvinceId> { details.WithdrewFromProvinceId, details.WithdrewToProvinceId },
                    singleDisplayedHero: displayedHero);
        }
    }
}
