using IRaCIS.Core.Domain.BaseModel;

namespace IRaCIS.Core.Domain.Models;
public interface IAggregateRoot;
public interface IEntity<TKey>
{
    abstract TKey Id { get; set; }

}

public interface IEntitySeqId
{
    public Guid SeqId { get; set; }
}

public abstract class Entity : IEntity<Guid>
{
    [Key]
    
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public Guid Id { get; set; }

    #region 领域事件 仅仅允许通过提供的方法进行操作

    [JsonIgnore]
    [NotMapped]
    private readonly List<DomainEvent> _domainEvents = [];

    [JsonIgnore]
    [NotMapped]
    public IReadOnlyCollection<DomainEvent> DomainEvents => _domainEvents.AsReadOnly();
    public void AddDomainEvent(DomainEvent domainEvent)
    {
        _domainEvents.Add(domainEvent);
    }

    public void RemoveDomainEvent(DomainEvent domainEvent)
    {
        _domainEvents.Remove(domainEvent);
    }

    public void ClearDomainEvents()
    {
        _domainEvents.Clear();
    }

    #endregion

    #region 领域命令 当前事务一起处理的,触发操作

    [JsonIgnore]
    private readonly List<DomainCommand> _domainCommands = [];

    [JsonIgnore]
    [NotMapped]
    public IReadOnlyCollection<DomainCommand> DomainCommands => _domainCommands.AsReadOnly();
    public void AddDomainCommand(DomainCommand domainCommand)
    {
        _domainCommands.Add(domainCommand);
    }

    public void RemoveDomainCommand(DomainCommand domainCommand)
    {
        _domainCommands.Remove(domainCommand);
    }

    public void ClearDomainCommands()
    {
        _domainCommands.Clear();
    }

    #endregion
}
#region 减少实体属性,增加基类

public abstract class BaseAddAuditEntity : Entity, IAuditAdd
{

    public Guid CreateUserId { get; set; }
    public DateTime CreateTime { get; set; }

    [ForeignKey("CreateUserId")]
    [JsonIgnore]
    public virtual UserRole CreateUserRole { get; set; }
}

public abstract class BaseAddDeleteAuditEntity : Entity, IAuditAdd, ISoftDelete
{

    public Guid CreateUserId { get; set; }
    public DateTime CreateTime { get; set; }
    public Guid? DeleteUserId { get; set; }
    public bool IsDeleted { get; set; }
    public DateTime? DeletedTime { get; set; }

    [ForeignKey("CreateUserId")]
    [JsonIgnore]
    public UserRole CreateUserRole { get; set; }
}

public abstract class BaseFullAuditEntity : Entity, IAuditUpdate, IAuditAdd
{
    public Guid CreateUserId { get; set; }
    public DateTime CreateTime { get; set; }
    public Guid UpdateUserId { get; set; }
    public DateTime UpdateTime { get; set; }

    [ForeignKey("CreateUserId")]
    [JsonIgnore]
    public UserRole CreateUserRole { get; set; }
}
public abstract class BaseFullDeleteAuditEntity : Entity, IAuditUpdate, IAuditAdd, ISoftDelete
{
    public Guid? DeleteUserId { get; set; }
    public bool IsDeleted { get; set; }
    public DateTime? DeletedTime { get; set; }
    public Guid CreateUserId { get; set; }
    public DateTime CreateTime { get; set; }
    public Guid UpdateUserId { get; set; }
    public DateTime UpdateTime { get; set; }

    [ForeignKey("CreateUserId")]
    [JsonIgnore]
    public UserRole CreateUserRole { get; set; }
}

public abstract class BaseAuditUpdateEntity : Entity, IAuditUpdate
{
    public Guid UpdateUserId { get; set; }
    public DateTime UpdateTime { get; set; }
}
#endregion