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

namespace eagle.Notifications.ARNNotifications {
    public static class ProvinceConqueredDetailsNotificationGenerator {
        public static readonly ARNNotificationGenerator Generator = GenerateNotification;

        private static IEnumerable<Notification> GenerateNotification(
                Net.Eagle0.Eagle.Common.Notification notification,
                IGameModel currentModel) {
            var playerId = currentModel.PlayerId;
            var details = notification.Details.ProvinceConqueredDetails;
            var province = currentModel.Provinces[details.ProvinceId];
            var winner = currentModel.MaybeDestroyedFaction(details.ConqueringFactionId);
            var loser = currentModel.MaybeDestroyedFaction(details.DefendingFactionId);

            var winnerHead = currentModel.Heroes[winner.FactionHeadId];
            var loserHead = currentModel.Heroes[loser.FactionHeadId];

            if (!playerId.HasValue || (playerId.Value != winner.Id && playerId.Value != loser.Id)) {
                yield return new Notification(
                        title: "Province Conquered",
                        text: $"{winner.Name} has conquered {province.Name} from {loser.Name}.",
                        singleProvinceId: details.ProvinceId,
                        displayedHeroes: new List<HeroView> { winnerHead, loserHead });
            }
        }
    }
}
