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

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

        private static class Placeholders {
            public static readonly DynamicTextPlaceholderName FactionHead =
                    new(nameof(FactionHead));
            public static readonly DynamicTextPlaceholderName NewBrother = new(nameof(NewBrother));
        }

        private static IEnumerable<Notification> GenerateNotifications(
                Net.Eagle0.Eagle.Common.Notification notification,
                IGameModel currentModel) {
            var details = notification.Details.SwearBrotherhoodDetails;
            var factionName = currentModel.FactionName(details.FactionId);
            var newBrother = currentModel.Heroes[details.NewBrotherHeroId];

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

            var affectedProvinces = currentModel.ProvincesForFaction(details.FactionId);

            var textTemplate = DynamicTextTemplate.Parsed(
                    $"{DynamicTextTemplate.Placeholder(Placeholders.NewBrother)} has sworn brotherhood with {factionName}'s leader {DynamicTextTemplate.Placeholder(Placeholders.FactionHead)}.\n\n");

            var heroPlaceholders = new List<DynamicPlaceholder> {
                DynamicPlaceholder.HeroName(Placeholders.NewBrother, newBrother, "A hero"),
                DynamicPlaceholder.HeroName(Placeholders.FactionHead, factionHead, "the leader")
            };

            yield return DynamicTextNotification.StreamingDynamicNotification(
                    title: "Swore Brotherhood",
                    textTemplate: textTemplate,
                    placeholders: heroPlaceholders,
                    llmId: notification.LlmId,
                    provinceIds: affectedProvinces,
                    displayedHeroes: new List<HeroView> { newBrother, factionHead });
        }
    }
}
