<?php

declare(strict_types=1);

namespace Drupal\flowdrop_memory\Attribute;

use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Attribute for MemoryBackend plugins.
 *
 * Use this attribute to register a custom memory storage backend.
 * Backends are discovered from the Plugin/MemoryBackend/ directory
 * in any module.
 *
 * Example usage:
 * @code
 * #[MemoryBackend(
 *   id: "redis",
 *   label: new TranslatableMarkup("Redis"),
 *   description: "Redis-backed persistent memory with TTL support.",
 *   persistent: TRUE,
 *   supports_ttl: TRUE,
 * )]
 * class RedisMemoryBackend extends AbstractMemoryBackend {
 *   // ...
 * }
 * @endcode
 *
 * @see \Drupal\flowdrop_memory\Plugin\MemoryBackend\MemoryBackendInterface
 * @see \Drupal\flowdrop_memory\Plugin\MemoryBackend\AbstractMemoryBackend
 *
 * @api
 */
#[\Attribute(\Attribute::TARGET_CLASS)]
final class MemoryBackend extends Plugin {

  /**
   * Constructs a new MemoryBackend attribute.
   *
   * @param string $id
   *   The plugin ID (e.g., "static", "cached", "entity").
   * @param \Drupal\Core\StringTranslation\TranslatableMarkup $label
   *   The human-readable label for this backend.
   * @param string $description
   *   A description of how this backend stores data.
   * @param bool $persistent
   *   Whether stored values survive the end of the current request.
   * @param bool $supports_ttl
   *   Whether this backend honours the $ttl parameter in set().
   * @param class-string|null $deriver
   *   (optional) The deriver class for dynamic plugin definitions.
   */
  public function __construct(
    public readonly string $id,
    public readonly TranslatableMarkup $label,
    public readonly string $description = '',
    public readonly bool $persistent = FALSE,
    public readonly bool $supports_ttl = FALSE,
    public readonly ?string $deriver = NULL,
  ) {}

}
