using System;
using System.Collections.Generic;
using System.Text;
using CafeTerrace.Models.Api;

namespace CafeTerrace.Utilities
{
    public static class Instance
    {
        private static LoginedUser _loginedUser;
        public static LoginedUser LoginedUser
        {
            set
            {
                if (value != null)
                    Plugin.Settings.CrossSettings.Current.AddOrUpdateValue("LoginedUser",
                        Newtonsoft.Json.JsonConvert.SerializeObject(value));
                else
                    Plugin.Settings.CrossSettings.Current.Remove("LoginedUser");
                _loginedUser = value;
            }
            get
            {
                if (_loginedUser == null)
                {
                    var userS = Plugin.Settings.CrossSettings.Current.GetValueOrDefault("LoginedUser", string.Empty);
                    if (!string.IsNullOrEmpty(userS))
                        _loginedUser = Newtonsoft.Json.JsonConvert.DeserializeObject<LoginedUser>(userS);
                    else
                        _loginedUser = null;
                }
                return _loginedUser;
            }
        }
    }
}
