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

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

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

        private static IEnumerable<Notification> GenerateNotifications(
                Net.Eagle0.Eagle.Common.Notification notification,
                IGameModel currentModel) {
            var playerId = currentModel.PlayerId;
            var details = notification.Details.InvitationAcceptedDetails;
            var offeringFaction = currentModel.MaybeDestroyedFaction(details.OfferingFactionId);
            var invitedFaction = currentModel.MaybeDestroyedFaction(details.InvitedFactionId);

            var offeringFactionHead = currentModel.Heroes[offeringFaction.FactionHeadId];
            var invitedFactionHead = currentModel.Heroes[invitedFaction.FactionHeadId];

            if (playerId.HasValue && playerId.Value == details.InvitedFactionId) {
                yield return Notification.StreamingNotification(
                        title: "Invitation Accepted",
                        prefixedText:
                        $"You have accepted an invitation from {currentModel.FactionName(details.OfferingFactionId)}.\n\n",
                        llmId: notification.LlmId,
                        provinceIds: new List<int>(),
                        displayedHeroes: new List<HeroView>());
            } else if (playerId.HasValue && playerId.Value == details.OfferingFactionId) {
                yield return Notification.StreamingNotification(
                        title: "Invitation Accepted",
                        prefixedText:
                        $"{currentModel.FactionName(details.InvitedFactionId)} has accepted your invitation.\n\n",
                        llmId: notification.LlmId,
                        provinceIds: new List<ProvinceId>(),
                        displayedHeroes: new List<HeroView> { invitedFactionHead });
            } else {
                yield return Notification.StreamingNotification(
                        title: "Faction Invited",
                        prefixedText:
                        $"{currentModel.FactionName(details.InvitedFactionId)} has accepted an invitation from {currentModel.FactionName(details.OfferingFactionId)}.\n\n",
                        llmId: notification.LlmId,
                        provinceIds: new List<ProvinceId>(),
                        displayedHeroes: new List<HeroView> { invitedFactionHead,
                        offeringFactionHead});
            }
        }
    }
}