using Hotline.Identity.Roles;
using Hotline.Share.Enums.Identity;
using Hotline.Users;
using SqlSugar;
using XF.Domain.Repository;

namespace Hotline.Identity.Accounts
{
    [SugarIndex("unique_account_username", nameof(Account.UserName), OrderByType.Desc, true)]
    public class Account : FullStateEntity
    {
        public string UserName { get; set; }

        [SugarColumn(IsNullable = true)]
        public string? NormalizedUserName { get; set; }

        [SugarColumn(IsNullable = true)]
        public string? Email { get; set; }

        [SugarColumn(IsNullable = true)]
        public string? NormalizedEmail { get; set; }

        public bool EmailConfirmed { get; set; }

        [SugarColumn(Length = 2000, IsNullable = true)]
        public string PasswordHash { get; set; }

        [SugarColumn(Length = 2000, IsNullable = true)]
        public string SecurityStamp { get; set; }

        [SugarColumn(Length = 2000, IsNullable = true)]
        public string ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString();

        [SugarColumn(IsNullable = true)]
        public string? PhoneNo { get; set; }

        public bool PhoneNoConfirmed { get; set; }

        /// <summary>
        /// Gets or sets the date and time, in UTC, when any user lockout ends.
        /// </summary>
        /// <remarks>
        /// A value in the past means the user is not locked out.
        /// </remarks>
        public DateTime? LockoutEnd { get; set; }

        /// <summary>
        /// Gets or sets a flag indicating if the user could be locked out.
        /// </summary>
        /// <value>True if the user could be locked out, otherwise false.</value>
        public bool LockoutEnabled { get; set; } = true;

        public int AccessFailedCount { get; set; }

        public string ClientId { get; set; }

        public string Name { get; set; }

        public bool PasswordChanged { get; set; }

        public EAccountStatus Status { get; set; }

        /// <summary>
        /// 账号类型
        /// </summary>
        public EAccountType AccountType { get; set; } = EAccountType.Personal;

        [SugarColumn(DefaultValue = "hotline_api")]
        public string Scope { get; set; }

        [Navigate(typeof(AccountRole), nameof(AccountRole.AccountId), nameof(AccountRole.RoleId))]
        public List<Role> Roles { get; set; }

        [Navigate(NavigateType.OneToOne, nameof(Id))]
        public User User { get; set; }
    }
}
