<?php

declare(strict_types=1);

namespace App\Domain\Time;

use DateTimeImmutable;
use DateTimeZone;

/**
 * Test-friendly clock. Construct with a fixed UTC datetime; `advance()`
 * rewinds it by a `DateInterval`-style spec. Tests use this to age
 * reports past decay or step through rate-limit refill windows.
 */
final class FixedClock implements Clock
{
    public function __construct(private DateTimeImmutable $now)
    {
        $this->now = $now->setTimezone(new DateTimeZone('UTC'));
    }

    public static function at(string $iso): self
    {
        return new self(new DateTimeImmutable($iso, new DateTimeZone('UTC')));
    }

    public function now(): DateTimeImmutable
    {
        return $this->now;
    }

    public function advance(string $modifier): void
    {
        $this->now = $this->now->modify($modifier);
    }
}
