using Furion.DatabaseAccessor;
using Furion.JsonSerialization;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace YBEE.EQM.Core;

/// <summary>
/// 用户
/// </summary>
[Comment("用户")]
public partial class SysUser : DEntityBase, IEntityTypeBuilder<SysUser>
{
    /// <summary>
    /// 机构ID
    /// </summary>
    [Comment("机构ID")]
    [Required]
    public short SysOrgId { get; set; }
    /// <summary>
    /// 名称
    /// </summary>
    [Comment("名称")]
    [Required, StringLength(200)]
    public string Name { get; set; }
    /// <summary>
    /// 头像地址
    /// </summary>
    [Comment("头像地址")]
    [StringLength(500)]
    public string Avatar { get; set; }
    /// <summary>
    /// 手机
    /// </summary>
    [Comment("手机")]
    [StringLength(16)]
    public string Mobile { get; set; }
    /// <summary>
    /// 电子邮箱
    /// </summary>
    [Comment("电子邮箱")]
    [StringLength(200)]
    public string Email { get; set; }
    /// <summary>
    /// 工号
    /// </summary>
    [Comment("工号")]
    [StringLength(200)]
    public string JobNumber { get; set; }
    /// <summary>
    /// 备注
    /// </summary>
    [Comment("备注")]
    [StringLength(200)]
    public string Remark { get; set; }
    /// <summary>
    /// 登录名
    /// </summary>
    [Comment("登录名")]
    [Required, StringLength(50)]
    public string Account { get; set; }
    /// <summary>
    /// 密码
    /// </summary>
    [Comment("密码")]
    [Required, StringLength(100)]
    public string Password { get; set; }
    /// <summary>
    /// 是否已激活
    /// </summary>
    [Comment("是否已激活")]
    [Required]
    public bool IsActivated { get; set; } = false;
    /// <summary>
    /// 激活时间
    /// </summary>
    [Comment("激活时间")]
    public DateTime? ActivateTime { get; set; }
    /// <summary>
    /// 最后登录IP
    /// </summary>
    [Comment("最后登录IP")]
    [MaxLength(21)]
    public string LastLoginIp { get; set; }
    /// <summary>
    /// 最后登录时间
    /// </summary>
    [Comment("最后登录时间")]
    public DateTime? LastLoginTime { get; set; }
    /// <summary>
    /// 用户自定义配置
    /// </summary>
    [Comment("用户自定义配置")]
    [Column(TypeName = "json")]
    public string Config { get; set; } = "{}";
    /// <summary>
    /// 用户权限
    /// </summary>
    [Comment("用户权限")]
    [Column(TypeName = "json")]
    public string Permission { get; set; } = JSON.Serialize(new UserPermission());

    /// <summary>
    /// 状态
    /// </summary>
    [Comment("状态")]
    [Required]
    public CommonStatus Status { get; set; }

    /// <summary>
    /// 一对一引用（机构）
    /// </summary>
    public virtual SysOrg SysOrg { get; set; }

    public void Configure(EntityTypeBuilder<SysUser> entityBuilder, DbContext dbContext, Type dbContextLocator)
    {
        entityBuilder.Ignore(t => t.CreateSysUser).Ignore(t => t.UpdateSysUser);
    }
}