<?php
	namespace Mocha\Core;

	use Mocha\Oms\Oms;

	use Mocha\Oop\Method;
	use Mocha\Oop\MethodBinding;

	use Phast\UUID;

	class InstanceReference
	{
		public Oms $OMS;
		public int $DatabaseId;
		public InstanceKey $InstanceKey;
		public UUID $GlobalIdentifier;

		public static function toInstanceKeys(array $instanceReferences) : array
		{
			$keys = [ ];
			foreach ($instanceReferences as $instanceReference)
			{
				$keys[] = $instanceReference->InstanceKey;
			}
			return $keys;
		}

		public function __construct(Oms $oms, int $databaseId, InstanceKey $instanceKey, UUID|string $globalIdentifier)
		{
			$this->OMS = $oms;
			$this->DatabaseId = $databaseId;
			$this->InstanceKey = $instanceKey;

			if (is_string($globalIdentifier))
			{
				$globalIdentifier = UUID::Parse($globalIdentifier);
			}
			$this->GlobalIdentifier = $globalIdentifier;
		}

		public function getRelatedInstances(InstanceReference $relationship)
		{
			$instances = [];
			return $instances;
		}
		public function getAttributeValue($attributeInstance, $defaultValue = null, $effectiveDate = null) : ?string
		{
			return $this->OMS->getAttributeValue($this, $attributeInstance, $defaultValue, $effectiveDate);
		}

		public function asMethod()
		{
			return new Method($this);
		}
		public function asMethodBinding()
		{
			return new MethodBinding($this);
		}

		public function __is_equal(InstanceReference $other)
		{
			return $this->GlobalIdentifier->__is_equal($other->GlobalIdentifier);
		}
		public function __is_not_equal(InstanceReference $other)
		{
			return !$this->__is_equal($other);
		}
	}
?>