<?php

declare(strict_types=1);

namespace PHPSTORM_META {

  // Entity types.
  registerArgumentsSet('entity_type_ids',
{% for type, definition in definitions %}
    '{{ type }}',
{% endfor %}
  );
  expectedArguments(\Drupal\KernelTests\KernelTestBase::installEntitySchema(), 0, argumentsSet('entity_type_ids'));
  expectedReturnValues(\Drupal\Core\Entity\EntityInterface::getEntityTypeId(), argumentsSet('entity_type_ids'));

  // Storages.
  override(
    \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage(0),
    map([
{% for type, definition in definitions %}
      '{{ type }}' => '{{ definition.storage }}',
{% endfor %}
    ]),
  );

  // View builders.
  override(
    \Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder(0),
    map([
{% for type, definition in definitions %}
  {% if definition.view_builder %}
      '{{ type }}' => '{{ definition.view_builder }}',
  {% endif %}
{% endfor %}
    ]),
  );

  // List builders.
  override(
    \Drupal\Core\Entity\EntityTypeManagerInterface::getListBuilder(0),
    map([
{% for type, definition in definitions %}
  {% if definition.list_builder %}
      '{{ type }}' => '{{ definition.list_builder }}',
  {% endif %}
{% endfor %}
    ]),
  );

  // Access control handlers.
  override(
    \Drupal\Core\Entity\EntityTypeManagerInterface::getAccessControlHandler(0),
    map([
{% for type, definition in definitions %}
      '{{ type }}' => '{{ definition.access_control }}',
{% endfor %}
    ]),
  );

  // Storage methods.
{% for definition in definitions %}
{# Using map() to work around PhpStorm bug. #}
{# @see https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001516519 #}
  override({{ definition.storage }}::loadMultiple(), map(['' => '{{ definition.class }}[]']));
  override({{ definition.storage }}::load(), map(['' => '{{ definition.class }}']));
  override({{ definition.storage }}::create(), map(['' => '{{ definition.class }}']));
  override({{ definition.class }}::loadMultiple(), map(['' => '{{ definition.class }}[]']));
  override({{ definition.class }}::load(), map(['' => '{{ definition.class }}']));
  override({{ definition.class }}::create(), map(['' => '{{ definition.class }}']));

{% endfor %}
}
