using System;
using Newtonsoft.Json;

namespace InABox.Logikal
{
    public abstract class LogikalRequest : LogikalObject
    {
        
        public static LogikalRequest FromMessage(LogikalMessage message)
        {
            if (message.Method == LogikalMethod.Connect)
                return JsonConvert.DeserializeObject<LogikalConnectRequest>(message.Payload);
            if (message.Method == LogikalMethod.Login)
                return JsonConvert.DeserializeObject<LogikalLoginRequest>(message.Payload);
            if (message.Method == LogikalMethod.Logout)
                return JsonConvert.DeserializeObject<LogikalLogoutRequest>(message.Payload);
            if (message.Method == LogikalMethod.Disconnect)
                return JsonConvert.DeserializeObject<LogikalDisconnectRequest>(message.Payload);
            throw new Exception($"Invalid Message Method: {message.Method}: {message.Payload}");
        }
        
        
    }
}