<?php

declare(strict_types=1);

namespace Drupal\flowdrop_session\Constants;

/**
 * Status constants for the FlowDrop Session Message entity.
 *
 * Message status lifecycle:
 * - PENDING: Message created, waiting to be processed.
 * - PROCESSING: Message is currently being processed.
 * - AWAITING_INPUT: Waiting for user input (human-in-the-loop).
 * - COMPLETED: Message processing finished successfully.
 * - FAILED: Message processing failed.
 * - CANCELLED: Message processing was explicitly cancelled.
 *
 * @internal
 */
final class MessageStatus {

  public const PENDING = 'pending';

  public const PROCESSING = 'processing';

  public const AWAITING_INPUT = 'awaiting_input';

  public const COMPLETED = 'completed';

  public const FAILED = 'failed';

  public const CANCELLED = 'cancelled';

  /**
   * Returns all allowed values keyed by machine name.
   *
   * Suitable for use in Drupal base field 'allowed_values' settings.
   *
   * @return array<string, string>
   *   Map of machine name to human-readable label.
   */
  public static function allowedValues(): array {
    return [
      self::PENDING => 'Pending',
      self::PROCESSING => 'Processing',
      self::AWAITING_INPUT => 'Awaiting Input',
      self::COMPLETED => 'Completed',
      self::FAILED => 'Failed',
      self::CANCELLED => 'Cancelled',
    ];
  }

  /**
   * Returns terminal statuses.
   *
   * Messages in these states are considered finished and will not be
   * processed further.
   *
   * @return string[]
   *   Array of terminal status values.
   */
  public static function terminalStatuses(): array {
    return [
      self::COMPLETED,
      self::FAILED,
      self::CANCELLED,
    ];
  }

}
