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

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

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

        private static class Placeholders {
            public static readonly DynamicTextPlaceholderName Hero1 = new(nameof(Hero1));
            public static readonly DynamicTextPlaceholderName Hero1Faction =
                    new(nameof(Hero1Faction));
            public static readonly DynamicTextPlaceholderName Hero2 = new(nameof(Hero2));
            public static readonly DynamicTextPlaceholderName Hero2Faction =
                    new(nameof(Hero2Faction));
        }

        private static IEnumerable<Notification> GenerateNotifications(
                Net.Eagle0.Eagle.Common.Notification notification,
                IGameModel currentModel) {
            var note = notification.Details.PrisonerExchangeDetails;
            var hero1 = currentModel.Heroes[note.Hero1Id];
            var hero2 = currentModel.Heroes[note.Hero2Id];

            string noteTitle = "Prisoners Exchanged";
            var textTemplate = DynamicTextTemplate.Parsed(
                    $"{DynamicTextTemplate.Placeholder(Placeholders.Hero1)} ({DynamicTextTemplate.Placeholder(Placeholders.Hero1Faction)}) and {DynamicTextTemplate.Placeholder(Placeholders.Hero2)} ({DynamicTextTemplate.Placeholder(Placeholders.Hero2Faction)}) have agreed to a prisoner exchange.");

            var heroPlaceholders = new List<DynamicPlaceholder> {
                DynamicPlaceholder.HeroName(Placeholders.Hero1, hero1, "A hero"),
                DynamicPlaceholder.FactionDisplayNameOrLeaderName(
                        Placeholders.Hero1Faction,
                        note.Hero1FactionId,
                        currentModel,
                        "Leader"),
                DynamicPlaceholder.HeroName(Placeholders.Hero2, hero2, "A hero"),
                DynamicPlaceholder.FactionDisplayNameOrLeaderName(
                        Placeholders.Hero2Faction,
                        note.Hero2FactionId,
                        currentModel,
                        "Leader")
            };

            yield return new DynamicTextNotification(
                    title: noteTitle,
                    textTemplate: textTemplate,
                    placeholders: heroPlaceholders,
                    provinceIds: new List<
                            ProvinceId> { note.Hero1ProvinceId, note.Hero2ProvinceId },
                    displayedHeroes: new List<HeroView> { hero1, hero2 });
        }
    }
}
