<?php
declare(strict_types=1);

namespace KimaAI\Lib;

use Symfony\Component\DependencyInjection\ContainerInterface;

final class EagerServices {
  /**
   * Eager services constructor.
   *
   * @param ContainerInterface $container The dependency injection container.
   * @param string[] $services_to_warm Service IDs to instantiate.
   */
  public function __construct(
    private ContainerInterface $container,
    private array $services_to_warm = []
  ) {}

  /**
   * Instantiates configured services.
   */
  public function initialize(): void {
    foreach ($this->services_to_warm as $id) {
      if ($this->container->has($id)) {
        // Instantiation triggers constructors that add WP hooks.
        $this->container->get($id);
      }
    }
  }
}
