<?php
	namespace Mocha\Oop\MethodImplementations;

	use Mocha\Core\InstanceReference;
	use Mocha\Core\KnownAttributeGuids;
	use Mocha\Core\KnownClassGuids;
	use Mocha\Core\KnownRelationshipGuids;
	use Mocha\Core\OmsContext;
	use Mocha\Oms\Oms;
	use Mocha\Oop\MethodImplementation;

	use Phast\UUID;

	class GetAttributeMethodImplementation extends MethodImplementation
	{
		protected function executeInternal(Oms $oms, OmsContext $context, InstanceReference $method, ?array $parms)
		{
			$returnsAttribute = $oms->getRelatedInstance($method, KnownRelationshipGuids::Get_Attribute_Method__has__Attribute);
			
			$forClass = $oms->getRelatedInstance($method, KnownRelationshipGuids::Method__for__Class);
			$targetInstance = $context->getWorkData($forClass);
			$value = $oms->getAttributeValue($targetInstance, $returnsAttribute);
			$context->workData[$returnsAttribute->GlobalIdentifier->__toString()] = $value;

			// echo ("[GA @" . $forClass->InstanceKey . ": inst (" . $targetInstance->InstanceKey . ") ; att " . $returnsAttribute->InstanceKey . " : " . $value . "]");
			return $returnsAttribute;
		}
	}

?>