<?php
/**
 * Logger — safe wrapper around error_log, gated by WP_DEBUG for debug output.
 *
 * Use sparingly. Production sites generally run with WP_DEBUG off, so debug()
 * is a no-op there. error() always logs, since a module failing to boot is
 * something a site owner may need to diagnose regardless of debug state.
 *
 * @package Platform\Helm\Core
 */

declare( strict_types = 1 );

namespace Platform\Helm\Core;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class Logger {

	public static function debug( string $message, array $context = [] ): void {
		if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
			return;
		}
		$line = '[Platform Helm] ' . $message;
		if ( ! empty( $context ) ) {
			$line .= ' | ' . wp_json_encode( $context );
		}
		error_log( $line ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
	}

	public static function error( string $message, ?\Throwable $e = null ): void {
		$line = '[Platform Helm][ERROR] ' . $message;
		if ( null !== $e ) {
			$line .= sprintf( ' | %s in %s:%d', $e->getMessage(), $e->getFile(), $e->getLine() );
		}
		error_log( $line ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
	}
}
