<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Scheduler;

use DateTimeImmutable;
use DateTimeZone;

final class SchedulerClock
{
    public function __construct(private readonly string $timezone = 'UTC') {}

    public function now(): DateTimeImmutable
    {
        return new DateTimeImmutable('now', new DateTimeZone($this->timezone));
    }

    public function addSeconds(int $seconds): DateTimeImmutable
    {
        return $this->now()->modify('+' . max(0, $seconds) . ' seconds');
    }

    public function parse(string $dateTime): DateTimeImmutable
    {
        return new DateTimeImmutable($dateTime, new DateTimeZone($this->timezone));
    }

    public function timezone(): string
    {
        return $this->timezone;
    }
}
