<?php

declare(strict_types=1);

namespace Drupal\ai;

use Drupal\ai\Plugin\AiPlatform\AiPlatformInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\ai\Attribute\AiPlatform;

/**
 * AiPlatform plugin manager.
 */
final class AiPlatformPluginManager extends DefaultPluginManager {

  /**
   * Constructs an AiPlatformPluginManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   of the dependencies scored by the discovery.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    parent::__construct(
      'Plugin/AiPlatform',
      $namespaces,
      $module_handler,
      AiPlatformInterface::class,
      AiPlatform::class
    );

    $this->alterInfo('ai_platform_info');
    $this->setCacheBackend($cache_backend, 'ai_platform_plugins');
  }

}
