<?php
/**
 * Global helper functions for Automation Web Platform (WAWP).
 *
 * @package automation-web-platform
 */

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

if ( ! function_exists( 'wawp_log_message' ) ) {
	/**
	 * Bridge function for logging to the unified log manager.
	 *
	 * @param string $phone      Recipient phone or identifier.
	 * @param string $message    The log message body.
	 * @param string $event_type The type of event (e.g., 'OTP Request').
	 * @param mixed  $details    Extra data/response to store.
	 * @param int    $user_id    Optional user ID.
	 * @param string $gateway    Gateway used ('whatsapp', 'email', etc).
	 * @param int    $related_id Optional related object ID (e.g., order ID).
	 * @param string $status     Log status ('success', 'failed', 'error').
	 */
	function wawp_log_message( $phone, $message, $event_type, $details, $user_id = null, $gateway = 'whatsapp', $related_id = null, $status = 'success' ) {
		$wawp = WAWP();
		if ( $wawp && $wawp->unified_log ) {
			$wawp->unified_log->add_activity_log(
				array(
					'phone'      => $phone,
					'message'    => $message,
					'event_type' => $event_type,
					'details'    => $details,
					'user_id'    => $user_id,
					'order_id'   => $related_id,
					'gateway'    => $gateway,
					'log_status' => $status,
				)
			);
		}
	}
}
