package com.social.media.domain.shared.kernel;

/**
 * Base class for aggregate roots in DDD
 */
public abstract class AggregateRoot<ID> {
    
    private ID id;
    
    protected AggregateRoot() {
        // For JPA
    }
    
    protected AggregateRoot(ID id) {
        this.id = id;
    }
    
    public ID getId() {
        return id;
    }
    
    protected void setId(ID id) {
        this.id = id;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        
        AggregateRoot<?> that = (AggregateRoot<?>) o;
        return id != null ? id.equals(that.id) : that.id == null;
    }
    
    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }
}
