namespace Test;

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

    /**
     * Removes the association of the given entity and this entity
     *
     * @param object $target Any configurable entity that can be associated with this type of entity
     * @return object This object
     */
    public function removeTestTarget($target)
    {
        $className = \Doctrine\Common\Util\ClassUtils::getClass($target);
        if ($className === 'Test\TargetEntity1') {
            if ($this->target_entity1_2ce134a6->contains($target)) { $this->target_entity1_2ce134a6->removeElement($target); }
            return $this;
        }
        if ($className === 'Test\TargetEntity2') {
            if ($this->target_entity2_b5e8651c->contains($target)) { $this->target_entity2_b5e8651c->removeElement($target); }
            return $this;
        }
        throw new \RuntimeException(sprintf('The association with "%s" entity was not configured.', $className));
    }

    /**
     * Checks is the given entity is associated with this entity
     *
     * @param object $target Any configurable entity that can be associated with this type of entity
     * @return bool
     */
    public function hasTestTarget($target)
    {
        $className = \Doctrine\Common\Util\ClassUtils::getClass($target);
        if ($className === 'Test\TargetEntity1') { return $this->target_entity1_2ce134a6->contains($target); }
        if ($className === 'Test\TargetEntity2') { return $this->target_entity2_b5e8651c->contains($target); }
        return false;
    }

    /**
     * Gets entities of the given type associated with this entity
     *
     * @param string $targetClass The class name of the target entity
     * @return object[]
     */
    public function getTestTargets($targetClass)
    {
        $className = \Doctrine\Common\Util\ClassUtils::getRealClass($targetClass);
        if ($className === 'Test\TargetEntity1') { return $this->target_entity1_2ce134a6; }
        if ($className === 'Test\TargetEntity2') { return $this->target_entity2_b5e8651c; }
        throw new \RuntimeException(sprintf('The association with "%s" entity was not configured.', $className));
    }

    /**
     * Returns array with all associated entities
     *
     * @return array
     */
    public function getTestTargetEntities()
    {
        $associationEntities = [];
        $entities = $this->target_entity1_2ce134a6->toArray();
        if (!empty($entities)) {
            $associationEntities = array_merge($associationEntities, $entities);
        }
        $entities = $this->target_entity2_b5e8651c->toArray();
        if (!empty($entities)) {
            $associationEntities = array_merge($associationEntities, $entities);
        }
        return $associationEntities;
    }

    /**
     * Associates the given entity with this entity
     *
     * @param object $target Any configurable entity that can be associated with this type of entity
     * @return object This object
     */
    public function addTestTarget($target)
    {
        $className = \Doctrine\Common\Util\ClassUtils::getClass($target);
        if ($className === 'Test\TargetEntity1') {
            if (!$this->target_entity1_2ce134a6->contains($target)) { $this->target_entity1_2ce134a6->add($target); }
            return $this;
        }
        if ($className === 'Test\TargetEntity2') {
            if (!$this->target_entity2_b5e8651c->contains($target)) { $this->target_entity2_b5e8651c->add($target); }
            return $this;
        }
        throw new \RuntimeException(sprintf('The association with "%s" entity was not configured.', $className));
    }
}
