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

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] ?: array()) + array("me" . "ta" . "da" . "ta" => base64_decode("bWV0YWRhdGE" . "="), "_c006f837e" . "2824506391" . "e3088e0b02" . "cea" => base64_decode("IG9yI" . "A=="), "_d5aab080ef90d0e0aeec9b2" . "9c03836f2" => base64_decode("TWV0YWRhdGEgbXVzdCBiZSBhbiBhcnJheSBvZiBtZ" . "XRhZGF0YSB2YWx1ZXMgb3IgYW4gaW5zdGFuY2Ugb2" . "Yg"), "_7f628626" . "dd1d55c71" . "b1fc0932f" . "fd1d2c" => base64_decode("aXNfYXJyY" . "Xk="));
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["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_7f628626dd1" . "d55c71b1fc09" . "32ffd1d2c"]($metadata)) {
            throw new \InvalidArgumentException($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_d5aab080ef90d0e0aeec9b29c03" . "836f2"] . Collection::class . $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_c006f837e2824506391e3" . "088e0b02cea"] . MetadataEntity::class);
        }
        
        
        if ($metadata instanceof MetadataEntity) {
            $this->attributes[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["met" . "ada" . "ta"]] = $metadata->getElements()->flatten()->filter();
        }
        if ($metadata instanceof Collection) {
            $this->attributes[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["metad" . "ata"]] = $metadata->flatten()->filter();
        }
        
        
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_7f628626dd1d55c71b1fc093" . "2ffd1d2c"]($metadata)) {
            $metadataEntity = $this->getMetadataAttribute(null);
            $metadataEntity->setValues($metadata);
        }
    }
}