<?php

declare(strict_types=1);

namespace Drupal\flowdrop_stategraph\Reducer;

/**
 * Reducer that replaces the current value entirely.
 *
 * This is the default reducer for state fields. It simply overwrites
 * the existing value with the new update value.
 *
 * Use cases:
 * - Current step or status tracking.
 * - Single-value fields like "currentNodeId".
 * - Boolean flags like "isComplete".
 *
 * Example:
 * @code
 * $reducer = new ReplaceReducer();
 *
 * $result = $reducer->reduce("old_value", "new_value");
 * // Result: "new_value"
 *
 * $result = $reducer->reduce(["old" => "data"], ["new" => "data"]);
 * // Result: ["new" => "data"]
 * @endcode
 *
 * @internal This class is not part of the public API and may change without notice.
 */
final class ReplaceReducer implements ReducerInterface {

  /**
   * {@inheritdoc}
   */
  public function getId(): string {
    return "replace";
  }

  /**
   * {@inheritdoc}
   */
  public function reduce(mixed $currentValue, mixed $updateValue): mixed {
    return $updateValue;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultValue(): mixed {
    return NULL;
  }

}
