using System;

namespace eagle {
    public sealed class GeneratedTextListener : IClientTextListener {
        private readonly string textId;
        private readonly string prefix;
        private readonly string suffix;
        private readonly int index;
        private readonly Action<int, string> onTextUpdate;

        public void OnTextUpdate(string text, bool completed) {
            onTextUpdate(index, $"{prefix}{text}{suffix}");
        }

        public string TextId() { return textId; }

        public GeneratedTextListener(
                string textId,
                string prefix,
                string suffix,
                int index,
                Action<int, string> callback) {
            this.textId = textId ?? throw new ArgumentNullException(nameof(textId));
            this.prefix = prefix ?? throw new ArgumentNullException(nameof(prefix));
            this.suffix = suffix ?? throw new ArgumentNullException(nameof(suffix));
            this.index = index;
            this.onTextUpdate = callback ?? throw new ArgumentNullException(nameof(callback));
        }
    }
}
