<?php

	namespace Mocha\Oop;

	use Mocha\Core\KnownRelationshipGuids;
	use Mocha\Core\OmsContext;
	use Mocha\Oms\Oms;
	use Mocha\Core\InstanceReference;

	class MethodBinding
	{
		public InstanceReference $MethodBindingInstance;

		public function __construct($oms, InstanceReference $methodBindingInst)
		{
			$this->OMS = $oms;
			$this->MethodBindingInstance = $methodBindingInst;
		}

		public function executeReturningInstanceSet(?array $parms = null) : null|array|InstanceReference
		{
			$context = new OmsContext();
			$method = $this->OMS->getRelatedInstance($this->MethodBindingInstance, $this->MethodBindingInstance->OMS->getInstanceByGlobalIdentifier(KnownRelationshipGuids::Method_Binding__executes__Method))->asMethod();
			if (is_array(value: $parms))
			{
				foreach ($parms as $gid => $value)
				{
					$context->setWorkData($gid, $value);
				}
			}
			$val = $method->execute($parms);
			return $val;
		}

	}
	
?>