<?php
/**
 * Class ShipmentDateFallback
 *
 * @package DhlPolska\Shipment
 */

namespace DhlPolska\Shipment;

use DateTimeImmutable;
use DateTimeZone;

/**
 * Provides fallback shipment dates in WordPress timezone.
 */
class ShipmentDateFallback {

	private DateTimeZone $timezone;

	public function __construct( ?DateTimeZone $timezone = null ) {
		$this->timezone = $timezone ?? wp_timezone();
	}

	public function today( ?DateTimeImmutable $now = null ): string {
		return $this->resolve_now( $now )->format( 'Y-m-d' );
	}

	public function tomorrow( ?DateTimeImmutable $now = null ): string {
		return $this->resolve_now( $now )
			->modify( '+1 day' )
			->format( 'Y-m-d' );
	}

	private function resolve_now( ?DateTimeImmutable $now = null ): DateTimeImmutable {
		return $now ?? new DateTimeImmutable( 'now', $this->timezone );
	}
}
