<?php

namespace WPD_Platform\Utils;

class Logger {
    /**
     * Log a debug message if WP_DEBUG is enabled
     *
     * @param string|array|object $message The message to log
     * @param string $context Optional context to prefix the message
     * @return void
     */
    public static function debug($message, $context = '') {
        if (!defined('WP_DEBUG') || !WP_DEBUG) {
            return;
        }

        $formatted_message = self::format_message($message, $context);
        error_log($formatted_message);
    }

    /**
     * Log an error message regardless of debug settings
     *
     * @param string|array|object $message The message to log
     * @param string $context Optional context to prefix the message
     * @return void
     */
    public static function error($message, $context = '') {
        $formatted_message = '[ERROR] ' . self::format_message($message, $context);
        error_log($formatted_message);
    }

    /**
     * Format the message for logging
     *
     * @param string|array|object $message
     * @param string $context
     * @return string
     */
    private static function format_message($message, $context = '') {
        $prefix = '[WPD Platform]';
        if (!empty($context)) {
            $prefix .= ' [' . $context . ']';
        }

        if (is_array($message) || is_object($message)) {
            $message = json_encode($message, JSON_PRETTY_PRINT);
        }

        return $prefix . ' ' . $message;
    }
} 