<?php

declare(strict_types=1);

namespace Drupal\ffmpeg_media\Enum;

/**
 * Conversion status for media processing pipeline.
 *
 * Replaces ProgressTrackerInterface::STATUS_* and ProgressData::STATUS_*
 * string constants with a type-safe backed enum.
 */
enum ConversionStatus: string {

  case Pending = 'pending';
  case Converting = 'converting';
  case Completed = 'completed';
  case Failed = 'failed';

  /**
   * Checks if this status represents a terminal (final) state.
   *
   * @return bool
   *   TRUE if the conversion has reached a final state.
   */
  #[\NoDiscard]
  public function isTerminal(): bool {
    return $this === self::Completed || $this === self::Failed;
  }

  /**
   * Gets the human-readable label for this status.
   *
   * @return string
   *   Translatable label string.
   */
  #[\NoDiscard]
  public function label(): string {
    return match ($this) {
      self::Pending => 'Pending',
      self::Converting => 'Converting',
      self::Completed => 'Completed',
      self::Failed => 'Failed',
    };
  }

  /**
   * Checks if this status represents an active (non-terminal) state.
   *
   * @return bool
   *   TRUE if the conversion is still in progress or waiting.
   */
  #[\NoDiscard]
  public function isActive(): bool {
    return !$this->isTerminal();
  }

  /**
   * Gets the valid status transitions from the current state.
   *
   * @return array<int, self>
   *   Array of statuses that this status can transition to.
   */
  #[\NoDiscard]
  public function transitionValues(): array {
    return match ($this) {
      self::Pending => [self::Converting, self::Failed],
      self::Converting => [self::Completed, self::Failed],
      self::Completed => [],
      self::Failed => [],
    };
  }

}
