<?php

declare( strict_types=1 );

namespace Brightfern\Support;

/**
 * Thin wrapper over the WooCommerce logger (WC → Status → Logs, source "brightfern-e-invoicing").
 * Centralised so every compliance-sensitive step — provider errors, validation
 * failures, inbound parse failures — lands in one searchable place. Degrades to
 * error_log when WooCommerce's logger isn't available (e.g. very early boot).
 */
final class Logger {

	private const SOURCE = 'brightfern-e-invoicing';

	public static function info( string $message ): void {
		self::log( 'info', $message );
	}

	public static function warning( string $message ): void {
		self::log( 'warning', $message );
	}

	public static function error( string $message ): void {
		self::log( 'error', $message );
	}

	private static function log( string $level, string $message ): void {
		if ( function_exists( 'wc_get_logger' ) ) {
			wc_get_logger()->log( $level, $message, array( 'source' => self::SOURCE ) );
			return;
		}
		// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
		error_log( '[brightfern][' . $level . '] ' . $message );
	}
}
