namespace Femto.Common.Domain;

public abstract class Entity
{
    private readonly ICollection<IDomainEvent> _domainEvents = [];

    protected void AddDomainEvent(IDomainEvent evt)
    {
        this._domainEvents.Add(evt);
    }

    public IList<IDomainEvent> DomainEvents => this._domainEvents.ToList();
    
    public void ClearDomainEvents() => this._domainEvents.Clear();

    protected void CheckRule(IRule rule)
    {
        if (!rule.Check())
            throw new RuleBrokenError(rule.Message);
    }
}
