<?php

declare(strict_types=1);

namespace Drupal\flowdrop_interrupt\Enum;

/**
 * Defines the status values for interrupt requests.
 *
 * @internal This class is not part of the public API and may change without notice.
 */
enum InterruptStatus: string {

  // Pending - Waiting for user response.
  case Pending = 'pending';

  // Resolved - User has provided a response.
  case Resolved = 'resolved';

  // Expired - The interrupt timed out without a response.
  case Expired = 'expired';

  // Cancelled - The interrupt was cancelled by the system or user.
  case Cancelled = 'cancelled';

  /**
   * Gets a human-readable label for the status.
   *
   * @return string
   *   The label.
   */
  public function label(): string {
    return match ($this) {
      self::Pending => 'Pending',
      self::Resolved => 'Resolved',
      self::Expired => 'Expired',
      self::Cancelled => 'Cancelled',
    };
  }

  /**
   * Checks if this status represents a terminal state.
   *
   * @return bool
   *   TRUE if the interrupt is in a terminal state.
   */
  public function isTerminal(): bool {
    return match ($this) {
      self::Pending => FALSE,
      self::Resolved, self::Expired, self::Cancelled => TRUE,
    };
  }

  /**
   * Checks if this status allows resolution.
   *
   * @return bool
   *   TRUE if the interrupt can be resolved.
   */
  public function canResolve(): bool {
    return $this === self::Pending;
  }

}
