<?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 GetInstanceSetBySystemRoutineMethodImplementation extends MethodImplementation
	{
		protected function executeInternal(Oms $oms, OmsContext $context, InstanceReference $method, ?array $parms)
		{
			$instSystemRoutine = $oms->getRelatedInstance($method, $oms->getInstanceByGlobalIdentifier(KnownRelationshipGuids::Get_Instance_Set_by_System_Routine_Method__uses__System_Instance_Set_Routine));
			$returnsWorkData = $oms->getRelatedInstance($method, KnownRelationshipGuids::Get_Instance_Set_by_System_Routine_Method__returns__Instance_Set);
			$singular = false; $oms->getAttributeValue($instSystemRoutine, $oms->getInstanceByGlobalIdentifier(KnownAttributeGuids::Singular));

			if ($instSystemRoutine->GlobalIdentifier->__is_equal(UUID::parse("430f572dd1164b0497b265a9e9230ce5")))
			{
				// get User for User Name parm
				// this System Attribute Routine has a required parm: `User Name [TX]` [4$11]

				$userName = $context->getWorkData(KnownAttributeGuids::UserName); // $parms[KnownAttributeGuids::UserName];
				$singular = true;
				if ($singular)
				{
					$value = $oms->getUserByUserName($userName);
				}
				else
				{
					$value = [ $oms->getUserByUserName($userName) ];
				}
				$context->setWorkData($returnsWorkData, $value);
			}
			
			return $returnsWorkData;
		}
	}

?>