<?php

declare(strict_types=1);

namespace Drupal\flowdrop_trigger\Enum;

/**
 * Overlap policy for scheduled (cron) workflow triggers.
 *
 * Controls what happens when a cron trigger fires while a previous pipeline
 * from the same workflow is still active (pending, running, or paused).
 *
 * @internal
 */
enum OverlapPolicy: string {

  // Do not start a new run while one is already active.
  case Skip = 'skip';

  // Queue one deferred run; fire it when the active run finishes.
  case Buffer = 'buffer';

  // Cancel the active pipeline(s) and start a new one.
  case Cancel = 'cancel';

  // Cancel the active pipeline(s) and all their active jobs, then start a
  // new one.
  case Terminate = 'terminate';

  /**
   * Gets a human-readable label.
   *
   * @return string
   *   The label.
   */
  public function label(): string {
    return match ($this) {
      self::Skip => 'Skip (do not start while a run is active)',
      self::Buffer => 'Buffer (queue one run; start it when the active run finishes)',
      self::Cancel => 'Cancel (cancel active pipeline, start new)',
      self::Terminate => 'Terminate (cancel active pipeline and its jobs, start new)',
    };
  }

}
