<?php

declare(strict_types=1);

namespace Australcode\Rewards\Service;

defined( 'ABSPATH' ) || exit;

/**
 * Pure helper for the points-expiration window (Pro). Computes the expires_at
 * stamp applied to Earn entries at credit time; 0 months (Free, via FeatureMap)
 * means points never expire (null stamp).
 */
final class PointsExpiry {

	/**
	 * @param int      $months Expiration window; <= 0 means never expire.
	 * @param int|null $now    Base timestamp (defaults to now); for testing.
	 */
	public static function expires_at( int $months, ?int $now = null ): ?string {
		if ( $months <= 0 ) {
			return null;
		}
		$base = $now ?? time();
		return gmdate( 'Y-m-d H:i:s', (int) strtotime( "+{$months} months", $base ) );
	}
}
