<?php

declare(strict_types=1);

namespace Drupal\ffmpeg_media\Exception;

use Drupal\ffmpeg_media\Enum\HardwareType;

/**
 * Wraps output execution failures with the last known hardware context.
 */
final class OutputExecutionException extends \RuntimeException {

  /**
   * Constructs the exception.
   *
   * @param string $message
   *   Exception message.
   * @param \Drupal\ffmpeg_media\Enum\HardwareType|null $hardwareType
   *   Last known hardware type used during output execution.
   * @param \Throwable|null $previous
   *   Previous exception.
   */
  public function __construct(
    string $message,
    private readonly ?HardwareType $hardwareType = NULL,
    ?\Throwable $previous = NULL,
  ) {
    parent::__construct($message, 0, $previous);
  }

  /**
   * Returns the last known hardware type from the failed execution run.
   */
  #[\NoDiscard]
  public function getHardwareType(): ?HardwareType {
    return $this->hardwareType;
  }

}
