<?php

namespace Drupal\user_provisioning;

use Drupal\Core\Entity\EntityInterface;
use Drupal\user_provisioning\Helpers\moUserProvisioningLogger;
use Drupal\user_provisioning\ProviderSpecific\EntityHandler\moUserProvisioningUserHandler;
use http\Exception\InvalidArgumentException;

/**
 * Factory for provisioning entity handlers.
 */
class moUserProvisioningEntityFactory {

  /**
   * Returns an entity handler for the given entity.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The Drupal entity to be provisioned.
   *
   * @return \Drupal\user_provisioning\ProviderSpecific\EntityHandler\moUserProvisioningUserHandler|moUserProvisioningEntityHandlerInterface
   *   The corresponding provisioning entity handler.
   */
  public static function getEntityHandler(EntityInterface $entity) {
    if ($entity->getEntityTypeId() == 'user') {
      $moLogger = new moUserProvisioningLogger();
      $moLogger->addLog("Creating and returning moUserProvisioningUserHandler object.", __LINE__, __FUNCTION__, __FILE__);
      return new moUserProvisioningUserHandler($entity);
    }
    else {
      throw new InvalidArgumentException();
    }
  }

}
