<?php

declare(strict_types=1);

namespace Drupal\Tests\native_observability_dashboard\Unit\ValueObject;

use Drupal\Tests\UnitTestCase;
use Drupal\native_observability_dashboard\ValueObject\TimeRange;

/**
 * Covers the dashboard time range value object.
 */
final class TimeRangeTest extends UnitTestCase {

  /**
   * Verifies accessors and duration calculation.
   */
  public function testAccessorsReturnAssignedValues(): void {
    $range = new TimeRange(100, 250, 'Custom range', 'custom');

    $this->assertSame(100, $range->getStartTimestamp());
    $this->assertSame(250, $range->getEndTimestamp());
    $this->assertSame('Custom range', $range->getLabel());
    $this->assertSame('custom', $range->getKey());
    $this->assertSame(150, $range->getDurationInSeconds());
  }

  /**
   * Verifies the minimum duration guard when end and start are equal.
   */
  public function testDurationIsNeverLowerThanOneSecond(): void {
    $range = new TimeRange(100, 100, 'Instant', 'instant');

    $this->assertSame(1, $range->getDurationInSeconds());
  }

}
