<?php
/**
 * Execution environment fingerprint.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Scheduler;

use ScheduledChanges\Provider\ProviderRegistry;
use ScheduledChanges\Support\Json;

/**
 * Captures version-sensitive runtime state for each run.
 */
final class EnvironmentFingerprint {
	public function generate( ProviderRegistry $providers ): string {
		global $wp_version;

		return hash(
			'sha256',
			Json::canonicalEncode(
				array(
					'plugin'    => defined( 'SCHEDULED_CHANGES_VERSION' ) ? SCHEDULED_CHANGES_VERSION : '',
					'schema'    => defined( 'SCHEDULED_CHANGES_SCHEMA_VERSION' ) ? SCHEDULED_CHANGES_SCHEMA_VERSION : '',
					'wordpress' => (string) $wp_version,
					'php'       => PHP_VERSION,
					'providers' => $providers->versions(),
				)
			)
		);
	}
}
