using System;
using Aitex.Core.Account;
using MECF.Framework.Common.CommonData;

namespace MECF.Framework.Common.Account.Extends
{
	[Serializable]
	public class UserContext : NotifiableItem
	{
		#region Variables

		private Credential _cred;
		private string _loginName;

		#endregion

		#region Properties

		public Credential Credential
		{
			get => _cred;
			set
			{
				_cred = value;
				InvokePropertyChanged(nameof(Token));
				InvokePropertyChanged(nameof(LoginName));
				InvokePropertyChanged(nameof(LoginTime));
			}
		}
		
		public Guid Token => _cred.Token;

		public string LoginName => _cred?.AccountInfo?.LoginName ?? "";
		
		public DateTime LoginTime => _cred?.LoginTime ?? DateTime.MinValue;

		public Role Role { get; set; }

		public DateTime LastAccessTime { get; set; }

		public string Language { get; private set; }

		public bool IsLogin { get; set; }

		#endregion

		#region Methods

		public void Clear()
		{
			_cred = Credential.Empty;
			Role = null;
			LastAccessTime = DateTime.MinValue;
			Language = string.Empty;
			IsLogin = false;
		}

		#endregion
    }
}
