using BukiVedi.Shared.Entities;
using BukiVedi.Shared.Models;
using ZeroLevel.Services.Serialization;

namespace BukiVedi.Shared.Services
{
    public static class UserTokenGenerator
    {
        public static string GenerateUserToken(Member account)
        {
            if (account.State == MemberState.Removed || account.State == MemberState.Banned) return string.Empty;
            var authData = new AuthTokenData { Login = account.Login, Timestamp = Timestamp.UtcNow };
            var data = MessageSerializer.Serialize<AuthTokenData>(authData);
            var encrypted = Cryptor.Encrypt(data);
            var token = Convert.ToBase64String(encrypted);
            return token;
        }
    }
}
