<?php

declare(strict_types=1);

namespace Drupal\flowdrop_interrupt\Enum;

/**
 * Defines the status values for interrupt requests.
 *
 * @api
 */
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';

  // Acknowledged - Terminal state for inward signals (Cancel) that have
  // been processed by the orchestrator. Distinct from Resolved (which
  // implies a user-provided response payload) and Cancelled (which means
  // the signal itself was abandoned without effect).
  case Acknowledged = 'acknowledged';

  /**
   * 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',
      self::Acknowledged => 'Acknowledged',
    };
  }

  /**
   * 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, self::Acknowledged => TRUE,
    };
  }

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

}
