<?php

declare(strict_types=1);

namespace Drupal\flowdrop_workflow\Diagnostic\Mutation;

/**
 * Re-anchors a node to a different node type.
 *
 * Rewrites the node's `data.metadata.node_type_id` anchor; the rest of the
 * node's metadata is re-derived from the new type on the next read, so only the
 * anchor is persisted here. The node's user config is left untouched — any
 * resulting config mismatch surfaces as its own finding on re-diagnosis.
 */
final class ReplaceNodeType implements WorkflowMutationInterface {

  /**
   * Constructs a ReplaceNodeType mutation.
   *
   * @param string $nodeId
   *   The id of the node to re-anchor.
   * @param string $newNodeTypeId
   *   The node type entity id to anchor to.
   */
  public function __construct(
    public readonly string $nodeId,
    public readonly string $newNodeTypeId,
  ) {}

  /**
   * {@inheritdoc}
   */
  public function summary(): string {
    return sprintf('Re-anchor node "%s" to node type "%s".', $this->nodeId, $this->newNodeTypeId);
  }

}
