<?php
	namespace Mocha\Oop;

	use Mocha\Core\InstanceReference;
	use Mocha\Core\OmsContext;
	use Mocha\Oms\Oms;
	use Phast\Utilities\Stopwatch;

	abstract class MethodImplementation
	{
		public InstanceReference $MethodInstance;

		protected abstract function executeInternal(Oms $oms, OmsContext $context, InstanceReference $method, ?array $parms);
		public function execute(Oms $oms, OmsContext $context, InstanceReference $method, ?array $parms) : mixed
		{
			array_push($context->CallStack, $method);

			trigger_error("MADI debug: entering " . get_class($this) . "::executeInternal");
			$stopwatch = new Stopwatch();
			$stopwatch->start();

			$retval = $this->executeInternal($oms, $context, $method, $parms);
			$stopwatch->stop();

			trigger_error("MADI debug: exiting " . get_class($this) . "::executeInternal (took " . $stopwatch->getElapsedTime() . "s)");

			array_pop($context->CallStack);
			return $retval;
		}
	}
?>