<?php

declare(strict_types=1);

namespace Drupal\flowdrop_trigger\Enum;

/**
 * Defines the categories for FlowDrop event types.
 *
 * @internal This enum is not part of the public API and may change without notice.
 */
enum EventCategory: string {

  // Entity-related events (insert, update, delete, presave).
  case Entity = 'entity';

  // User-related events (login, logout).
  case User = 'user';

  // Form-related events (submit, validate).
  case Form = 'form';

  // Cron-related events.
  case Cron = 'cron';

  // Integration-related events (external platform invocations).
  case Integration = 'integration';

  /**
   * Resolves a category value to its string representation.
   *
   * Handles both EventCategory enum instances and plain strings, providing
   * a single conversion point for code that receives either form.
   *
   * @param self|string $value
   *   An EventCategory enum instance or string value.
   *
   * @return string
   *   The string value of the category.
   */
  public static function toString(self|string $value): string {
    return $value instanceof self ? $value->value : $value;
  }

  /**
   * Gets a human-readable label for the event category.
   *
   * @return string
   *   The label.
   */
  public function label(): string {
    return match ($this) {
      self::Entity => 'Entity',
      self::User => 'User',
      self::Form => 'Form',
      self::Cron => 'Cron',
      self::Integration => 'Integration',
    };
  }

}
