<?php
/**
 * Form SMS Notification Utility
 *
 * @package miniorange-sms-order-notification-otp-verification/notifications/formsmsnotification/helper
 */

namespace WCSMSOTP\Notifications\FormSMSNotification\Helper;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
use WCSMSOTP\Helper\MoUtility;

/**
 * This class is used to define some plugin wide utility
 * functions. The functions described here are all static
 * in nature so that it's accessible without an instance.
 */
if ( ! class_exists( 'FormSMSNotificationUtility' ) ) {
	/**
	 * FormSMSNotificationUtility class
	 */
	class FormSMSNotificationUtility {

		/**
		 * Get the Phone of the first Admin user. This is used as
		 * the recipient of the admin SMS notifications if no
		 * phone number is saved for the notification.
		 *
		 * @return string
		 */
		public static function get_phone_number_key() {
			$recipient_value       = '';
			$notification_settings = mowc_get_fmsn_option( 'notification_settings_option' );
			if ( ! empty( $notification_settings ) && is_object( $notification_settings ) ) {
				$sms_settings = $notification_settings->get_mo_contact_form7_notif();
				if ( is_object( $sms_settings ) && isset( $sms_settings->recipient ) ) {
					$unserialized = maybe_unserialize( $sms_settings->recipient );
					if ( false !== $unserialized ) {
						$recipient_value = is_array( $unserialized )
							? implode( ';', array_map( 'sanitize_text_field', $unserialized ) )
							: sanitize_text_field( $unserialized );
					}
				}
			}
			return $recipient_value;
		}


		/**
		 * Checks if the customer is registered or not and shows a message on the page
		 * to the user so that they can register or login themselves to use the plugin.
		 */
		public static function is_addon_activated() {
			MoUtility::is_addon_activated();
		}
	}
}
