<?php
namespace Claromentis\Core\ORM\Behaviors;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"] ?: array()) + array("_7f628626dd1d55c71b1fc0932ff" . "d1d2c" => base64_decode("aXNfY" . "XJyYX" . "k="), "_c006f837e2824506391e308" . "8e0b02cea" => base64_decode("IG9y" . "IA=="), "_b255ebaf" . "d5b8bb451" . "10cd2db06" . "04fa44" => base64_decode("bWV0YWRhd" . "GE="), "_d5aab080e" . "f90d0e0aee" . "c9b29c0383" . "6f2" => base64_decode("TWV0YWRhdGEgbXVzdCBiZSBhbiBhcnJheSBvZiBtZXRhZGF0YSB2YWx1" . "ZXMgb3IgYW4gaW5zdGFuY2Ugb2Yg"));
use Analogue\ORM\EntityCollection;
use Analogue\ORM\Mappable;
use Illuminate\Support\Collection;
use ProxyManager\Proxy\ProxyInterface;
use Claromentis\Core\ORM\Entity\Metadata as MetadataEntity;






















trait Metadata
{
    
    
    
    
    
    
    protected $metadata;
    
    
    
    
    
    
    public abstract function getMetadataAggregation() : int;
    
    
    
    
    
    
    public function getMetadataObjectId() : int
    {
        return $this->id;
    }
    
    
    
    
    
    
    public function getMetadataSetId() : int
    {
        return 0;
    }
    
    
    
    
    
    
    
    
    
    
    public function getMetadataAttribute($elements) : MetadataEntity
    {
        
        
        if (!$this->metadata) {
            $aggregation = $this->getMetadataAggregation();
            $object_id = $this->getMetadataObjectId();
            $set_id = $this->getMetadataSetId();
            $this->metadata = new MetadataEntity($this, $aggregation, $object_id, $set_id);
            $this->metadata->elements = $elements ?: new EntityCollection();
        }
        return $this->metadata;
    }
    
    
    
    
    
    
    
    
    
    public function setMetadataAttribute($metadata)
    {
        if (!$metadata instanceof MetadataEntity && !$metadata instanceof Collection && !$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_7f628626dd1d55c71b1fc09" . "32ffd1d2c"]($metadata)) {
            throw new \InvalidArgumentException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d5aab080ef9" . "0d0e0aeec9b2" . "9c03836f2"] . Collection::class . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_c006f837e28245" . "06391e3088e0b02" . "cea"] . MetadataEntity::class);
        }
        
        
        if ($metadata instanceof MetadataEntity) {
            $this->attributes[$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_b255ebafd5b" . "8bb45110cd2d" . "b0604fa44"]] = $metadata->getElements()->flatten()->filter();
        }
        if ($metadata instanceof Collection) {
            $this->attributes[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_b255ebafd5" . "b8bb45110cd" . "2db0604fa44"]] = $metadata->flatten()->filter();
        }
        
        
        if ($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_7f628626dd1d55c71b1f" . "c0932ffd1d2c"]($metadata)) {
            $metadataEntity = $this->getMetadataAttribute(null);
            $metadataEntity->setValues($metadata);
        }
    }
}