<?php

declare(strict_types=1);

namespace Drupal\flowdrop_workflow_executor\Exception;

use Drupal\flowdrop\DTO\ValidationResult;

/**
 * Thrown when a launch is refused because the definition is invalid.
 *
 * Distinct from its parent {@see WorkflowLaunchException}, which signals a
 * server-side launch failure (job generation/dispatch). This subclass means
 * the caller's stored definition failed structural validation — a 4xx
 * condition, not a 5xx — so the HTTP boundary can report it with the same
 * structured detail the save path returns rather than as a generic error.
 *
 * Carries the {@see ValidationResult} so callers can surface per-error codes
 * and locators without re-running the validator.
 *
 * Public API — part of the launcher's BC surface.
 */
class WorkflowLaunchValidationException extends WorkflowLaunchException {

  public function __construct(
    string $message,
    private readonly ValidationResult $result,
  ) {
    parent::__construct($message);
  }

  /**
   * The validation result that caused the launch to be refused.
   *
   * @return \Drupal\flowdrop\DTO\ValidationResult
   *   The failed result, carrying the per-error codes, messages and locators.
   */
  public function getResult(): ValidationResult {
    return $this->result;
  }

}
