<?php

declare(strict_types=1);

namespace Drupal\flowdrop_runtime\Event;

use Drupal\flowdrop_runtime\DTO\Runtime\NodeExecutionContext;
use Drupal\flowdrop_runtime\DTO\Runtime\NodeExecutionResult;
use Symfony\Contracts\EventDispatcher\Event;

/**
 * Event dispatched after a node is executed (success or failure).
 *
 * @internal
 */
class NodePostExecuteEvent extends Event {

  /**
   * The event name.
   */
  const NAME = 'flowdrop.node.post_execute';

  /**
   * Constructs a new NodePostExecuteEvent.
   *
   * @param array $nodeData
   *   The node data array.
   * @param string $executionId
   *   The execution ID.
   * @param string $workflowId
   *   The workflow ID.
   * @param \Drupal\flowdrop_runtime\DTO\Runtime\NodeExecutionContext $context
   *   The execution context.
   * @param \Drupal\flowdrop_runtime\DTO\Runtime\NodeExecutionResult|null $result
   *   The execution result, or NULL if an error occurred.
   * @param string|null $error
   *   The error message, or NULL if successful.
   */
  public function __construct(
    public readonly array $nodeData,
    public readonly string $executionId,
    public readonly string $workflowId,
    public readonly NodeExecutionContext $context,
    public readonly ?NodeExecutionResult $result = NULL,
    public readonly ?string $error = NULL,
  ) {}

}
