package net.paslavsky.msm.domain

import javax.persistence.MappedSuperclass
import javax.persistence.EmbeddedId
import javax.persistence.Version

/**
 * Abstract class that represent Domain objects of the MSM
 *
 * @author Andrey Paslavsky
 * @version 1.0
 */
MappedSuperclass
public abstract class DomainObject {
    public EmbeddedId var id: ID = ID()
    public Version var version: Int = -1

    override fun toString(): String = "${javaClass.getSimpleName()}#$id"
    override fun hashCode(): Int = 37 + 17 * (id xor (id shl 32)).toInt()
    override fun equals(other: Any?): Boolean = when {
        other == null -> false
        this identityEquals other -> true
        other is DomainObject && javaClass == other.javaClass -> id == other.id && version == other.version
        else -> false
    }
}