<?php

declare(strict_types=1);

namespace Drupal\flowdrop_workflow_executor\Enum;

/**
 * Defines the status values for workflow execution results.
 *
 * @api
 */
enum WorkflowExecutionStatus: string {

  case Completed = 'completed';
  case Running = 'running';
  case Pending = 'pending';
  case Paused = 'paused';
  case Failed = 'failed';
  case Timeout = 'timeout';

  /**
   * Gets a human-readable label for the status.
   *
   * @return string
   *   The label.
   */
  public function label(): string {
    return match ($this) {
      self::Completed => 'Completed',
      self::Running => 'Running',
      self::Pending => 'Pending',
      self::Paused => 'Paused',
      self::Failed => 'Failed',
      self::Timeout => 'Timed Out',
    };
  }

  /**
   * Checks if this is a terminal status.
   *
   * @return bool
   *   TRUE if the execution has reached a final state.
   */
  public function isTerminal(): bool {
    return match ($this) {
      self::Completed, self::Failed, self::Timeout => TRUE,
      self::Running, self::Pending, self::Paused => FALSE,
    };
  }

  /**
   * Checks if this status indicates success.
   *
   * @return bool
   *   TRUE if the execution completed successfully.
   */
  public function isSuccess(): bool {
    return $this === self::Completed;
  }

}
