using System;
using System.Collections.Generic;
using System.Text;
using iElection.Models.Config;
using Xamarin.Essentials;

namespace iElection.Utilities
{
    public class UserUtilities
    {
        private string _userToken;
        public string UserToken
        {
            get
            {
                if (_userToken == null)
                    _userToken = Preferences.Get(Settings.UserToken, string.Empty);
                return _userToken;
            }
            set
            {
                Preferences.Set(Settings.UserToken, value);
                _userToken = value;
            }
        }
        private string _fullName;
        public string FullName
        {
            get
            {
                if (_fullName == null)
                    _fullName = Preferences.Get(Settings.FullName, string.Empty);
                return _fullName;
            }
            set
            {
                Preferences.Set(Settings.FullName, value);
                _fullName = value;
            }
        }

        public void LogOut()
        {
            _userToken = null;
            Preferences.Set(Settings.UserToken, null);
            _fullName = null;
            Preferences.Set(Settings.FullName, null);
        }
        public bool IsAuthorized
        {
            get
            {
                if (string.IsNullOrEmpty(UserToken))
                    return false;
                return true;
            }
        }
    }
}
