<?php

declare(strict_types=1);

namespace Drupal\flowdrop_workflow\Diagnostic\Mutation;

/**
 * Sets a single key on a node's user config (`data.config`) to a value.
 *
 * Used to reset a key to its schema default and to re-expose a port (by setting
 * the reserved `ports` config key to a recomputed structure).
 */
final class SetNodeConfig implements WorkflowMutationInterface {

  /**
   * Constructs a SetNodeConfig mutation.
   *
   * @param string $nodeId
   *   The id of the node whose config is edited.
   * @param string $key
   *   The config key to set.
   * @param mixed $value
   *   The value to set.
   * @param string $summary
   *   A human-readable summary of why this is set (the value alone rarely
   *   reads well in the confirm interstitial, so the diagnostic supplies one).
   */
  public function __construct(
    public readonly string $nodeId,
    public readonly string $key,
    public readonly mixed $value,
    private readonly string $summary,
  ) {}

  /**
   * {@inheritdoc}
   */
  public function summary(): string {
    return $this->summary;
  }

}
