<?php

declare(strict_types=1);

namespace Drupal\flowdrop_workflow\Diagnostic;

/**
 * A dry-run summary of what applying a set of selections would change.
 *
 * Produced by {@see \Drupal\flowdrop_workflow\Service\WorkflowDoctorInterface}
 * previewRemedies() to power the confirm interstitial. It is purely
 * descriptive: no mutation is applied and nothing is saved. The plan lists the
 * human-readable change lines (one per mutation), flags whether any are
 * destructive, and records selections skipped because their finding vanished
 * since the report was rendered.
 */
final class RemedyPlan {

  /**
   * Constructs a RemedyPlan.
   *
   * @param list<string> $changes
   *   Human-readable summaries of each mutation that would be applied.
   * @param bool $destructive
   *   TRUE when any selected remedy removes a node or edge.
   * @param list<string> $skipped
   *   Finding ids whose selection was skipped (the finding is no longer
   *   present, so the remedy no longer applies).
   */
  public function __construct(
    private readonly array $changes,
    private readonly bool $destructive,
    private readonly array $skipped = [],
  ) {}

  /**
   * The change lines, one per mutation.
   *
   * @return list<string>
   *   The summaries.
   */
  public function changes(): array {
    return $this->changes;
  }

  /**
   * Whether applying the plan would make any change.
   *
   * @return bool
   *   FALSE when every selection resolved to no mutation (e.g. all were "leave
   *   as is" or their findings vanished).
   */
  public function hasChanges(): bool {
    return $this->changes !== [];
  }

  /**
   * Whether any change in the plan is destructive.
   *
   * @return bool
   *   TRUE when a node or edge would be removed.
   */
  public function isDestructive(): bool {
    return $this->destructive;
  }

  /**
   * Finding ids whose selection was skipped.
   *
   * @return list<string>
   *   The skipped finding ids.
   */
  public function skipped(): array {
    return $this->skipped;
  }

}
