<?php

declare(strict_types=1);

namespace Drupal\Tests\native_observability\Unit\Service;

use Drupal\Tests\UnitTestCase;
use Drupal\native_observability\Service\UlidRequestIdGenerator;

/**
 * Covers the ULID-based request identifier generator.
 *
 * These tests focus on the public contract only:
 * - the generated identifier must match the expected ULID shape;
 * - consecutive identifiers should remain unique in normal execution.
 */
final class UlidRequestIdGeneratorTest extends UnitTestCase {

  /**
   * Verifies that the generated request identifier follows the ULID format.
   */
  public function testGenerateReturnsUlidLookingIdentifier(): void {
    $generator = new UlidRequestIdGenerator();

    $generated = $generator->generate();

    $this->assertSame(26, strlen($generated));
    $this->assertMatchesRegularExpression('/^[0-9A-HJKMNP-TV-Z]{26}$/', $generated);
  }

  /**
   * Verifies that sequential calls do not return the same identifier.
   */
  public function testGenerateReturnsUniqueIdentifiers(): void {
    $generator = new UlidRequestIdGenerator();

    $first = $generator->generate();
    $second = $generator->generate();

    $this->assertNotSame($first, $second);
  }

}
