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

namespace eagle.Notifications {
    using ProvinceId = Int32;

    public class DynamicTextNotification : Notification, IDisposable {
        public override bool IsTextDynamic => true;

        private readonly DynamicTextBinding textBinding;

        public DynamicTextNotification(
                string title,
                DynamicTextTemplate textTemplate,
                IEnumerable<DynamicPlaceholder> placeholders,
                List<ProvinceId> provinceIds,
                List<HeroView> displayedHeroes,
                bool shouldAppend = true,
                string llmId = null)
            : this(title,
                   new DynamicTextBinding(textTemplate, placeholders),
                   provinceIds,
                   displayedHeroes,
                   shouldAppend,
                   llmId) {}

        private DynamicTextNotification(
                string title,
                DynamicTextBinding textBinding,
                List<ProvinceId> provinceIds,
                List<HeroView> displayedHeroes,
                bool shouldAppend,
                string llmId)
            : base(title, textBinding.Text, provinceIds, displayedHeroes, shouldAppend, llmId) {
            this.textBinding = textBinding;
            this.textBinding.TextChanged += SetText;
        }

        public DynamicTextNotification(
                string title,
                DynamicTextTemplate textTemplate,
                IEnumerable<DynamicPlaceholder> placeholders,
                ProvinceId singleProvinceId,
                List<HeroView> displayedHeroes,
                bool shouldAppend = true)
            : this(title,
                   textTemplate,
                   placeholders,
                   new List<ProvinceId> { singleProvinceId },
                   displayedHeroes,
                   shouldAppend) {}

        public void Dispose() {
            textBinding.TextChanged -= SetText;
            textBinding.Dispose();
        }

        public static DynamicTextNotification StreamingDynamicNotification(
                string title,
                DynamicTextTemplate textTemplate,
                IEnumerable<DynamicPlaceholder> placeholders,
                string llmId,
                List<ProvinceId> provinceIds,
                List<HeroView> displayedHeroes) {
            return new DynamicTextNotification(
                    title: title,
                    textTemplate: textTemplate,
                    placeholders: placeholders,
                    provinceIds: provinceIds,
                    displayedHeroes: displayedHeroes,
                    shouldAppend: false,
                    llmId: llmId);
        }
    }
}
