using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace YBEE.EQM.Core
{
    /// <summary>
    /// 自定义实体基类
    /// </summary>
    public abstract class DEntityBase : DEntityBase<int, MasterDbContextLocator>
    {
    }

    public abstract class DEntityBase<TKey> : DEntityBase<TKey, MasterDbContextLocator>
    {
    }

    public abstract class DEntityBase<TKey, TDbContextLocator1> : PrivateDEntityBase<TKey> where TDbContextLocator1 : class, IDbContextLocator
    {
    }

    public abstract class PrivateDEntityBase<TKey> : IPrivateEntity
    {
        /// <summary>
        /// 主键
        /// </summary>
        [Comment("主键")]
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public virtual TKey Id { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        [Comment("创建时间")]
        [Required]
        public virtual DateTime CreateTime { get; set; }
        /// <summary>
        /// 更新时间
        /// </summary>
        [Comment("更新时间")]
        public virtual DateTime? UpdateTime { get; set; }
        /// <summary>
        /// 创建人ID
        /// </summary>
        [Comment("创建人ID")]
        [Required]
        public virtual int CreateSysUserId { get; set; }
        /// <summary>
        /// 修改者Id
        /// </summary>
        [Comment("修改者Id")]
        public virtual int? UpdateSysUserId { get; set; }
        /// <summary>
        /// 软删除
        /// </summary>
        [Comment("软删除标记")]
        [Required, JsonIgnore]
        public virtual bool IsDeleted { get; set; } = false;

        /// <summary>
        /// 一对一引用（创建人）
        /// </summary>
        public virtual SysUser CreateSysUser { get; set; }
        /// <summary>
        /// 一对一引用（更新人）
        /// </summary>
        public virtual SysUser UpdateSysUser { get; set; }
    }
}