using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Abp.Authorization.Users;
using Abp.Extensions;
using JetBrains.Annotations;

namespace YGNT.Exam.Authorization.Users
{
    public class User : AbpUser<User>
    {
        public const string DefaultPassword = "123qwe";

        /// <summary>
        /// 电子邮箱
        /// </summary>
        [CanBeNull]
        public new string EmailAddress { get; set; }

        [CanBeNull]
        public new string NormalizedEmailAddress { get; set; }

        /// <summary>
        /// 全名
        /// </summary>
        public new string FullName => Surname + " " + Name;

        [Required]
        public new string PhoneNumber { get; set; }

        public override void SetNormalizedNames()
        {
            NormalizedUserName = UserName.ToUpperInvariant();

            NormalizedEmailAddress = EmailAddress?.ToUpperInvariant();
        }

        public static string CreateRandomPassword()
        {
            return Guid.NewGuid().ToString("N").Truncate(16);
        }

        public static User CreateTenantAdminUser(int tenantId, string emailAddress)
        {
            var user = new User
            {
                TenantId = tenantId,
                UserName = AdminUserName,
                Name = AdminUserName,
                Surname = AdminUserName,
                EmailAddress = emailAddress,
                Roles = new List<UserRole>(),
                PhoneNumber = "1"
            };

            user.SetNormalizedNames();

            return user;
        }
    }
}
