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 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 = "";
            string textTemplate = "";

            var heroPlaceholders = new Dictionary<string, (string nameTextId, string fallback)> {
                { "SpottedOutlaw", (spottedOutlaw.NameTextId, "An outlaw") }
            };

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

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