<?php

declare(strict_types=1);

namespace Drupal\flowdrop_workflow_executor\Message;

use Drupal\flowdrop_interrupt\Enum\InterruptType;
use Drupal\flowdrop_interrupt\Message\AbstractInterruptMessage;

/**
 * Sentinel interrupt that resolves when a dispatched sub-pipeline completes.
 *
 * Created synchronously by WorkflowNode after it dispatches a sub-workflow.
 * The parent's WorkflowExecution interrupt (a LinkedInterruptMessage)
 * links to this sentinel's UUID, so the generic
 * LinkedInterruptResolvedSubscriber cascades the parent's resolution when
 * this sentinel resolves.
 *
 * The handler stores `subPipelineId` in the entity's `pipelineId` column
 * so PipelineCompletionSubscriber can find this sentinel by matching
 * against the `PipelineCompletedEvent`'s executionId (= the completed
 * pipeline's id). The match works whether the sub-pipeline lives in its
 * own session or shares the parent's.
 *
 * @api
 */
final class PipelineCompletionSentinelMessage extends AbstractInterruptMessage {

  public function __construct(
    string $message,
    public readonly string $subPipelineId,
    array $context = [],
  ) {
    parent::__construct(InterruptType::PipelineCompletion, $message, $context);
  }

}
