namespace Test;

class Entity
{
    /**
     * Checks if this entity can be associated with the given target entity type
     *
     * @param string $targetClass The class name of the target entity
     * @return bool
     */
    public function supportAssociationTarget($targetClass)
    {
        $className = \Doctrine\Common\Util\ClassUtils::getRealClass($targetClass);
        if ($className === 'Test\TargetEntity1') { return true; }
        if ($className === 'Test\TargetEntity2') { return true; }
        return false;
    }

    /**
     * Gets the entities this entity is associated with
     *
     * @return object[]
     */
    public function getAssociationTargets()
    {
        $targets = [];
        $entity = $this->target_entity1_78f809cf;
        if ($entity) {
            $targets[] = $entity;
        }
        $entity = $this->target_entity2_e1f15875;
        if ($entity) {
            $targets[] = $entity;
        }
        return $targets;
    }

    /**
     * Sets the entity this entity is associated with
     *
     * @param object $target Any configurable entity that can be associated with this type of entity
     * @return object This object
     */
    public function addAssociationTarget($target)
    {
        if (null === $target) { $this->resetAssociationTargets(); return $this; }
        $className = \Doctrine\Common\Util\ClassUtils::getClass($target);
        if ($className === 'Test\TargetEntity1') { $this->target_entity1_78f809cf = $target; return $this; }
        if ($className === 'Test\TargetEntity2') { $this->target_entity2_e1f15875 = $target; return $this; }
        throw new \RuntimeException(sprintf('The association with "%s" entity was not configured.', $className));
    }

    private function resetAssociationTargets()
    {
        $this->target_entity1_78f809cf = null;
        $this->target_entity2_e1f15875 = null;
    }
}

