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

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

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

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

        private static IEnumerable<Notification> GenerateNotifications(
                Net.Eagle0.Eagle.Common.Notification notification,
                IGameModel currentModel) {
            var details = notification.Details.OutlawSpottedDetails;
            var province = currentModel.Provinces[details.ProvinceId];
            var spottedOutlaw = currentModel.Heroes[details.OutlawHeroId];

            string noteTitle = "";
            DynamicTextTemplate textTemplate;

            var heroPlaceholders = new List<DynamicPlaceholder> { DynamicPlaceholder.HeroName(
                    Placeholders.SpottedOutlaw,
                    spottedOutlaw,
                    "An outlaw") };

            if (province.RulingFactionId is FactionId fid && fid == currentModel.PlayerId) {
                noteTitle = "Outlaw Spotted";
                textTemplate = DynamicTextTemplate.Parsed(
                        $"{DynamicTextTemplate.Placeholder(Placeholders.SpottedOutlaw)} has been spotted in {province.Name}!");
            } else {
                noteTitle = "Outlaw Departed";
                textTemplate = DynamicTextTemplate.Parsed(
                        $"{DynamicTextTemplate.Placeholder(Placeholders.SpottedOutlaw)} has left our territory for {province.Name}.");
            }

            yield return new DynamicTextNotification(
                    title: noteTitle,
                    textTemplate: textTemplate,
                    placeholders: heroPlaceholders,
                    singleProvinceId: province.Id,
                    displayedHeroes: new List<HeroView> { spottedOutlaw });
        }
    }
}
