using System;
using Telegram.Bot;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;

namespace Monithor.api.Alerting {
	public class TelegramTarget : ITarget {
		public TelegramTarget(TelegramBotClient client, string chatId, IMonitor monitor, string statusPageRoute, string displayName) {
			_client          = client;
			_chatId          = chatId;
			Monitor          = monitor;
			_statusPageRoute = statusPageRoute;
			_displayName     = displayName;
		}
		
		public IMonitor Monitor { get; set; }

		private readonly TelegramBotClient _client;
		private readonly string            _chatId;
		private readonly string            _statusPageRoute;
		private readonly string            _displayName;

		public async void SendMessage() {
			var statusPageBtn = new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl("Open status page", $"https://{_statusPageRoute}"));
			var message       = General.GetMessage(Monitor, _displayName);
			try {
				await _client.SendTextMessageAsync(_chatId, message, ParseMode.Default, replyMarkup: statusPageBtn);
			}
			catch (Exception e) {
				Console.WriteLine(e);
			}
		}
	}
}