<?php

declare(strict_types=1);

namespace Drupal\ffmpeg_media\Exception;

/**
 * Exception thrown when concurrent conversion limit is reached.
 */
final class ConcurrentLimitException extends \RuntimeException {

  /**
   * Constructs a ConcurrentLimitException.
   *
   * @param int $currentCount
   *   Current number of active conversions.
   * @param int $maxLimit
   *   Maximum allowed concurrent conversions.
   */
  public function __construct(
    public readonly int $currentCount,
    public readonly int $maxLimit,
  ) {
    parent::__construct(
      sprintf(
        'Concurrent conversion limit reached (%d/%d). Please try again later.',
        $currentCount,
        $maxLimit,
      ),
    );
  }

  /**
   * Creates an exception with context.
   *
   * @param int $currentCount
   *   Current number of active conversions.
   * @param int $maxLimit
   *   Maximum allowed concurrent conversions.
   *
   * @return self
   *   New exception instance.
   */
  public static function limitReached(int $currentCount, int $maxLimit): self {
    return new self($currentCount, $maxLimit);
  }

}
