<?php

declare(strict_types=1);

namespace Drupal\ffmpeg_media\Enum;

/**
 * Circuit breaker states for hardware acceleration reliability.
 *
 * Replaces CircuitBreakerInterface::STATE_* string constants.
 *
 * States:
 * - Closed: Normal operation, requests pass through.
 * - Open: Too many failures, requests fail fast (skip hardware).
 * - HalfOpen: After timeout, allow one test request.
 */
enum CircuitBreakerState: string {

  case Closed = 'closed';
  case Open = 'open';
  case HalfOpen = 'half-open';

  /**
   * Checks if the circuit allows requests to pass through.
   *
   * @return bool
   *   TRUE if requests should proceed (Closed or HalfOpen).
   */
  #[\NoDiscard]
  public function allowsRequests(): bool {
    return $this !== self::Open;
  }

  /**
   * Checks if the circuit is in a failure state.
   *
   * @return bool
   *   TRUE if the circuit is open (blocking requests).
   */
  #[\NoDiscard]
  public function isBlocking(): bool {
    return $this === self::Open;
  }

}
